Product Documentation
Cadence SKILL++ Object System Reference
Product Version IC23.1, June 2023

initializeInstance

initializeInstance( 
g_instance 
[ u_?initArg1    value1 ]
[ u_?initArg2    value2 ] 
... 
)
=> t

Description

Initializes the newly created instance of a class. The initializeInstance is a generic function which is called by the makeInstance function. Methods can be defined for a particular class to allow complex initialization to be performed on the object.

Any slot initialized with an @initarg is initialized before initializeInstance is called. The @initform values are used by the root primary method. So, if a primary method is defined, you should remember to callNextMethod() within that method to ensure that any @initforms are used. The usual practice is to perform any additional initialization in an @after method as all standard initialization has been performed by the time it is called. This @after method can then take additional keyword arguments, or initialize a slot based on the values of other slots.

Arguments

g_instance

A symbol denoting an instance. The instance must be created using makeInstance.

u_?initArg1 value1 u_?initArg2 value2

initArg1 specifies the initial value for argument1 of the instance. Similarly for the pair u_initArg2 and so forth.

Value Returned

t

The instance has been initialized.

Examples

defclass(A ()
  (
    (x @initarg x @initform 1)
    (y @initarg y @initform 2)
    (product)
  )
)
defmethod( initializeInstance @after ((obj A) @key product @rest args)
  if(product then
    obj->product = product
  else
    obj->product = obj->x * obj->y
  )
  printf("initializeInstance : A : was called with args - obj == '%L'
    product == '%L' rest == '%L'\n" obj product args)
  printf("  object initialized to: %L\n" obj->??)
)
makeInstance('A)
    initializeInstance : A : was called with args - obj == 'stdobj@0x2d61020'      product == 'nil' rest == 'nil'
  object initialized to: (x 1 y 2 product 2)
=> stdobj@0x2d61020
makeInstance('A ?x 5 ?y 10)
    initializeInstance : A : was called with args - obj == 'stdobj@0x2d61038'      product == 'nil' rest == '(?x 5 ?y 10)'
  object initialized to: (x 5 y 10 product 50)
=> stdobj@0x2d61038
makeInstance('A ?product 30)
    initializeInstance : A : was called with args - obj == 'stdobj@0x2d61050'      product == '30' rest == 'nil'
  object initialized to: (x 1 y 2 product 30)
=> stdobj@0x2d61050

Related Topics

Classes and Instances


Return to top
 ⠀
X