Class Operators — (., ..)
instance.variable = value
instance.variable
instance..variable = value
instance..variable
instanceAn instance of a class.
variableAn instance variable name.
valueA new value to write to the instance variable.
The value argument.
These operators assign and evaluate object instance values, using
familiar C/C++ structure/class reference syntax. The
instance and its instance
variable are separated by a period and the
assignment is made using the = assignment operator.
Using two periods between instance and
variable makes the reader interpret the instance
variable.
Using either the . or the ..
without the = assignment operator causes the
variable to be evaluated at that instance.
Gamma>class cmpny { name; address; }(defclass cmpny nil [][address name])Gamma>company = new(cmpny);{cmpny (address) (name)}Gamma>company.name = "Acme Widgets";"Acme Widgets"Gamma>company.name;"Acme Widgets"Gamma>var = symbol("name");nameGamma>company..var;"Acme Widgets"Gamma>
Here is an example of how the .. syntax can be used to
allow an instance of one class to access a method of another class. This can
be useful if a parent and child widget have different methods with the same
name, and you want an instance of one to use the method of the other.
Gamma>class A{}(defclass A nil [][])Gamma>class B{}(defclass B nil [][])Gamma>class C B{}(defclass C B [][])Gamma>method A.get (){princ("Class A's method.\n");}(defun A.get (self) (princ "Class A's method.\n"))Gamma>method B.get (){princ("Class B's method.\n");}(defun B.get (self) (princ "Class B's method.\n"))Gamma>a = new(A);{A }Gamma>a.get();Class A's method. tGamma>b = new(B);{B }Gamma>b.get();Class B's method. tGamma>(b..A.get)();Class A's method. tGamma>(a..B.get)();Class B's method. tGamma>c = new(C);{C }Gamma>(c..A.get)();Class A's method. tGamma>(c..B.get)();Class B's method. tGamma>