class
class — defines a class.
class class_name [parent]
{
[instance_var [= initial_value];]
...
[static:class_var[= initial_value];]
...
}
class_nameThe name of the new class.
parentThe parent (base) class.
class_varClass variable definition.
instance_varInstance 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_valueInitial value given to instance_var, if
none then nil
is assigned to that instance variable.
A class definition.
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>
Class Operators, class_add_cvar,
class_add_ivar, method, new