Let's assume that X is the class (or type) of x, and that Y is the class of y. The way to install a method for the addition of an instance x of class X to an instance y of class Y is with a statement of the form
X + Y := (x,y) -> ...where ... represents the body of the function, consisting of suitable code for the operation at hand.
The method installed by the code above is automatically inherited by subclasses of X and Y. Here is a brief description of the way this works. Suppose X is the parent of P and Y is the parent of X. When a sum p+q is evaluated where the class of p is P and the class of q is Q, then the binary method for P+Q is applied, unless there isn't one, in which case the binary method for P+Y is applied, unless there isn't one, in which case the binary method for X+Q is applied, unless there isn't one, in which case the binary method for P+Q is applied. In general this search for a binary method continues all the way up the chain of parents to the topmost ancestor of everything, which is called Thing.
As an extreme example of inheritance, the code
Thing + Thing := (x,y) -> ...will install a binary method for adding any two things, which will take effect as a last resort whenever more a specifically defined method isn't found.
The new function also uses a ternary lookup table to find the initialization function for the new thing, and should be thought of as a ternary operator. The initialization function for a new expression created by
new Z of x from yis
lookup(NewMethod,Z,X,Y)and can be installed with
new Z of X from Y := (z,y) -> ...where z denotes the new hash table of class Z and parent x provided to the routine by the system.
Go to main index.
Go to concepts index.