14 The Built-In Macros and Special Operators
let
variables =
init ;
variablebnf | (
variable-listbnf
)
expressionbnf
let
creates local bindings for the variables, and initializes them to the values returned by init. The bindings are visible for the remainder of the smallest enclosing implicit body.
The first value returned by the init is bound to the first variable, the second value to the second variable, etc. The last variable may be preceded by #rest
, in which case it is bound to a sequence containing all the remaining values.
Each variable is a variable-name or a variable-name followed by a specializer.
If more than one binding is defined, the variables are enclosed in parentheses and separated by commas.
let start = 0; let (whole-part, remainder) = truncate(amount); let (first-value, #rest rest-values) = get-inital-values();Local variables may be specialized. This ensures that their value will always be of a given type. An attempt to initialize or assign the variable to a value not of that type will signal an error of type
<type-error>
.
let elapsed-time :: <integer> = 0; let the-front-window :: <window> = front-window(); let(whole-part :: <integer>, remainder :: <real>) = truncate(amount);
local { [ method ] name parameter-list [ body ] end [ method ] [ name ] } ,+
variable-namebnf
parameter-listbnf
bodybnf
local
is creates local methods which may be mutually recursive and self-recursive.
Each name creates a new local binding. The binding is initialized to a new method specified by the parameter-list and body. In addition to being visible for the remainder of the smallest enclosing implicit body, the bindings created for the names are visible to the parameter-lists and bodies of all the methods created by the local
declaration.
The parameter-list is a standard method parameter list. A complete description of parameter lists is given in "Parameter Lists" on page 82.
The body is an implicit body.
let handler
condition = handler
| ( type { ,option }*)
expressionbnf
| init-option
test: expressionbnf
init-arguments: expressionbnf
expressionbnf
let handler
establishes a new condition handler which is in effect for the duration of the execution of the remainder of the smallest enclosing implicit body. Unlike the local declarations let
and local
, let handler
does not create any bindings.
<set-and-continue>
restart condition will have the signaled <unbound-slot>
condition in a slot, and the handler's test will check for it. (These class names are invented for this example and are not part of the specification.)
do-handler
.) There can be at most one init-option.
signal
of a restart. The function can decline to handle the condition by tail-recursively calling the next-handler function with no arguments. test-option and handler are distinct so that handler applicability can be tested without actually handling (which might take a non-local exit). One use for this is constructing a list of available restart handlers.
There is no "condition wall," i.e., when executing handler the set of available handlers is not reset to the handlers that were in effect when the let handler
was entered.
Implementations are encouraged to implement let handler
in a way that optimizes establishing a handler for both speed and space, even if that increases the cost of signaling. The assumption is that most of the time a handler will never be used, because the exception it is looking for will never occur.
type, handler, test-option, and init-option are executed before execution of the rest of the enclosing body begins.
Generated with Harlequin WebMaker