Previous page Table of Contents Next page
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) := zis equivalent to
f:=(x, y, z)
x.y := zis equivalent to
y:=(x, z)
w.x(y) := zis equivalent to
x:=(w, y, z)
list(a, b, c) := dis 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) := coordsis equivalent to
block def temp is list = coords x:=(pt, temp[0]) y:=(pt, temp[1])
Previous page Table of Contents Next page