method class.method_name ([argument [, argument]...]) statement
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++.
![]() |
|
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-2006 by Cogent Real-Time Systems, Inc. All rights reserved.