Methods

  • After slot list, series of expressions, separated by periods.

  • Arguments indicated with argument slots:
    (| :x. :y | x squared + y squared)

  • Shorthand for method arguments:
      add: el = (addLast: el)
      add: = (| :el | addLast: el)
      + = (| :pt | ((x + pt x) @ (y + pt y))
      + pt = ((x + pt x) @ (y + pt y))

Methods

After 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 methods

Some 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.

[ Previous ] [ Index ] [ Next ]