method class.method_name ([argument [, argument]...]) statement
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:
instance.method_name(arguments);
which is the familiar object.method syntax used in C++.
The method syntax creates a new method for a particular class. It is an error to omit the class. The argument list for method is identical to the argument list for function.
|
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>
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.