14 The Built-In Macros and Special Operators
Operator | Description | Page | |
---|---|---|---|
:= | Stores a new value in a location. | 395 | |
| | Returns the value of the first of two operands which is true.Returns the value of the first of two operands which is true. | 397 | |
& | Executes a second operand and returns its values if the value of the first operand is true. | 398 |
:=
[Special Operator]
:= new-value
operandbnf
operandbnf
<object>
.
:=
stores new-value in place and returns new-value.place may be a variable, a getter function or macro with a corresponding setter, a slot access, or an element reference.
new-value may be any operand. It is executed, and its value is stored in place.
In all cases, new-value must be an appropriate type for place or an error is signaled.
The new-value of an assignment statement is executed first, followed by the place (assuming the place requires any execution, which will only be true if it is not a binding name).
:=
cannot be used to create bindings, only to change their values.) An error is also signaled if place is a binding specialized to a type and the new-value is not of that type.
define variable *number* = 10; *number*Þ 10 *number* := *number* + 10;
Þ 20 *number*
Þ 20
:=
will invoke the corresponding setter function. Given a binding named fun, the corresponding setter is the binding named fun-setter
in the current environment.
:=
maps place to place-setter
without regard for whether place is a function or a macro. It does not expand a macro call on the left-hand side before determining the setter.
With the exception of the order of execution and a guaranteed return value, the following three expressions are equivalent:
*top-view*.subviews := generate-subviews() subviews(*top-view*) := generate-subviews() subviews-setter(generate-subviews(), *top-view*)(The differences are as follows: the execution time of
subviews-setter
is undefined in the first two expressions but defined in the last; the first two expressions will return the value of the call to generate-subviews
while the last will return the value of the call to subviews-setter
.)
name(arg1,...argn ) := new-valuebehaves exactly the same as
begin let temp = new-value; name-setter(temp, arg1,...argn ); temp endThis is true regardless of whether
name
and name-setter
are functions or macros. Here temp stands for a variable with a unique name. If name-setter
is a macro, it is responsible for the order of executation of arg1,...argn
.
The same considerations apply to arg.name := new-value
.
[]
can be used as syntax for element
and aref
, []
and :=
can be used as syntax for element-setter
and aref-setter
. For example, the following three expressions are equivalent:
foo[2] := "quux" element (foo, 2) := "quux" element-setter ("quux", foo, 2).
|
[Special Operator]
| another
operandbnf
operandbnf
<object>
.
|
(logical or) executes one. If the first value of one is true, that value is returned. Otherwise another is executed and its values are returned.
&
[Special Operator]
& another
Þ values
operandbnf
operandbnf
<object>
.
&
(logical and) executes one. If the first value returned by one is false, #f
is returned and another is not executed. Otherwise, another is executed and its values are returned.
Generated with Harlequin WebMaker