Programming Language for Old Timers


by David A. Moon
February 2006 .. September 2008

Comments and criticisms to dave underscore moon atsign alum dot mit dot edu.


Previous page   Table of Contents   Next page


Assignment

The assignment operator := is an infix operator macro whose right-hand side is an expression. The value of the operator is the value of the right-hand side. If the right-hand side returns multiple values, the operator only uses and returns the first value.

If the left-hand side is a name, the name's definition in the current scope must be assignable. The definition's value is changed to the value of the right-hand side. The macro's expansion is an assignment P-expression.

If the left-hand side is a slot-reference that reads a slot, the expansion is a slot-assignment that writes the same slot.

If the left-hand side is an invocation, the function being invoked must be a name. The macro's expansion is an invocation of the corresponding setter function, whose name is the original function's name suffixed with ":=" and whose context is the original function's context. The setter function takes one additional argument, which is the right-hand side, and must return the value of that argument. If the definition of the setter function is a macro rather than a function, the macro is expanded and the result is the expansion of the := macro. In this case the syntax accepted by the macro must be the syntax of a function call, with comma-separated arguments in parentheses.

Example:

f(x, y) := z
is equivalent to
f:=(x, y, z)


Previous page   Table of Contents   Next page