|
MethodsAfter a method's slot list (which is optional) comes the body of the method. This is a sequence of expressions, separated by periods. The value returned by the method is the value of the last expression.Each expression will usually be a message send (as there is no point in merely mentioning a literal, except as the last expression).
Arguments to methodsSome methods require arguments. The formal arguments are indicated with argument slots:
(| :x. :y | x squared + y squared ) This defines a method object which accepts two arguments, accessible as x and y in the method. When defining a method slot, a short form is provided. These are equivalent:
add: = (| :el | addLast: el) add: el = (addLast: el) + = (| :pt | ((x + pt x) @ (y + pt y)) + pt = ((x + pt x) @ (y + pt y))The long form is rarely used in practice. |