The class for which this method is defined.
The name of the method.
The argument list for this method. This does not include the implied argument self, nor is self defined when the arguments are bound as the method is called.
The body code statment for this method. Within this statement the special variable self is defined as the instance on which this method is being applied.
This statement defines a method function for a given class. If a method already exists for this class with this name, the previous definition will be replaced. If a method of the same name exists for any parent (base) class of the given class, it will be overridden for instances of this class only. In Gamma methods are run using the syntax:
which is the familiar object.method syntax used in C++.
![]() |
|
Gamma> class RegPolygon{sides; length;}
(defclass RegPolygon nil [][length sides])
Gamma> method RegPolygon.perimeter (){.sides * .length;}
(defun RegPolygon.perimeter (self) (* (@ self sides) (@ self length)))
Gamma> class Square RegPolygon {sides = 4;}
(defclass Square RegPolygon [][length (sides . 4)])
Gamma> method Square.area (){sqr(self.length);}
(defun Square.area (self) (sqr (@ self length)))
Gamma> sqB = new(Square);
{Square (length) (sides . 4)}
Gamma> sqB.length = 3;
3
Gamma> sqB.perimeter();
12
Gamma> sqB.area();
9
Gamma>
See the PID Controller Class section of the PID Emulator chapter in the Cogent Tools Demo and Tutorials book for an example of this statement used in context.