The name of the new class.
The parent (base) class.
Class variable definition.
Instance variable definition. This is provided in the form of a list of variable definitions. Each variable definition is either a variable name or a list which contains a variable name and a default value expression. Whenever a new instance is formed, the default value expression is evaluated to the default value. If no default value is given, the instance variable's value will be nil.
Initial value given to instance_var, if none then nil is assigned to that instance variable.
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>
See the The PID Controller Class section of the PID Emulator chapter (Tutorial One) in the Cogent Tools Demo and Tutorials book for an example of this statement used in context.