class_add_ivar (class, variable, init_value?, type?)
A class.
A symbol to be used as the instance variable name.
Any Gamma or Lisp expression to be used as an initial value.
An integer number which will be stored with the instance variable. This type is not used by the interpreter, and may be anything.
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 method. The instance sqB does not have "color" as an instance variable because it was created before the instance variable "color" was added. |
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>
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.