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 call is the value of the right-hand side.

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 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 syntax accepted by the macro must be the syntax of a function call, with comma-separated arguments in parentheses. The macro is expanded and the result is the expansion of the := macro.

An invocation on the left-hand side can be used to assign to a slot or other functionally-accessed location. It can also be used for destructuring, when the left-hand side invokes a constructor. For example, corresponding to the list constructor is the list:= destructuring macro which expands into assignments of parts of the list to its arguments. See the Destructuring section for more discussion.

Examples:

f(x, y) := z
is equivalent to
f:=(x, y, z)
x.y := z
is equivalent to
y:=(x, z)
w.x(y) := z
is equivalent to
x:=(w, y, z)
list(a, b, c) := d
is a destructuring and is equivalent to
block
  def temp is list = d
  a := temp[0]
  b := temp[1]
  c := temp[2]
and
list(pt.x, pt.y) := coords
is equivalent to
block
  def temp is list = coords
  x:=(pt, temp[0])
  y:=(pt, temp[1])


Previous page   Table of Contents   Next page