class_add_ivar
class_add_ivar — adds an instance variable to a class.
class_add_ivar (class, variable, init_value?, type?)
classA class.
variableA symbol to be used as the instance variable name.
init_valueAny Gamma or Lisp expression to be used as an initial value.
typeAn integer number which will be stored with the instance variable. This type is not used by the interpreter, and may be anything.
The value of the init_value.
This function dynamically adds an instance variable to a class. All instances of that class which are created after this call will contain this instance variable. All instances created before this call will not contain this instance variable. This function is typically called on a class before any instances are created. It is too late to call this function within an instance constructor. All subclasses of this class will inherit the new instance variable. If the ivar already exists on the class, the only effect of this function is to change the default value.
![]() | |
This example is based on the class and method developed in |
Gamma>class_add_ivar(Square, #color, "red", 12);"red"Gamma>sqC = new(Square);{Square (color . "red") (length) (sides . 4)}Gamma>sqB;{Square (length . 3) (sides . 4)}Gamma>