class class_name [parent]
{
[instance_var [= initial_value];]
...
[static:class_var[= initial_value];]
...
}
This function constructs a class definition and binds the class-name symbol in the current scope to refer to that class. The class mechanism allows only a single parent (base) class. None of the arguments to class is evaluated. If instance_vars are defined with the same names as inherited variables, the inherited variables are overridden and cannot be accessed by instances of this class.
![]() |
|
This example creates two classes: a base class, RegPolygon; and a class derived from it, Square. RegPolygon has two attributes: sides and length. When Square is created, its parent (base) class (RegPolygon) is explicitly assigned. In addition, the attibute sides is assigned a value of 4.
Gamma> class RegPolygon{sides; length;}
(defclass RegPolygon nil [][length sides])
Gamma> class Square RegPolygon {sides = 4;}
(defclass Square RegPolygon [][length (sides . 4)])This example creates a class with instance variables and class variables.
Gamma> class Other {ivar1; ivar2; static: cvar1; cvar2;}
(defclass Other nil [cvar1 cvar2][ivar1 ivar2])
Gamma>
Copyright © 1995-2012 by Cogent Real-Time Systems, Inc. All rights reserved.