next up previous
Next: Data Modification Up: User-level Constructs Previous: Control Structure

Variables

New local variables may be created and bound to values anywhere a statement may appear, using the let statement.



let

New variable binding.
Syntax:

 (let¯ ( var <-  val)

statement

statement ... )

Elements:
var ---
A new variable name. This name must not exist as a local variable name at the point where the let statement occurs. However, it may exist as the name of a static data item, in which case that meaning will be shadowed within the body of the let.
val ---
An expression to whose value var will be bound.
statement, statement, ... ---
Statements to execute in the scope where var is available as a variable.

Description:

Let creates a new local variable var and binds it to a value. The body of the let may change the value of var, but the value of var at the end of the body must match the value that the val expression has at the time the body ends. Otherwise program behavior will be unpredictable thereafter. The val expression is actually evaluated twice, once forwards before the body, to generate the value to bind to var, and once backwards after the body, to uncompute this value.

Actually the current implementation of let does require the value of val and all its subexpressions to remain the same at both the start and end of the body. Future implementations may relax this restriction.

Other forms of the let construct currently exist, but are not currently documented as user-level constructs.



Michael Frank
Mon Nov 3 16:33:38 EST 1997