let
and let*
.
let
is lexical, that is the let
expression, but their extent is
indefinite (see anonymous functions).
let
looks like this:
exp-i
, i<=m, is evaluated and the
resulting values are associated with the corresponding id-i
.
Subsequently, the expressions exp-i
, m<i<=n are
evaluated in order. The result of the let
expression is the result of exp-n
.
x
is initialized
with the value 3
and y
with the value
1000.00000000000
. The result is the sum of
x
cubed and y
squared.
let*
is the same as let
, as
shown above, with the substitution of let*
for
let
. The semantic difference with let*
is
that each expression exp-i
can refer to the results of earlier
initialization expressions. Whereas with let
, the
exp-i
were evaluated first and then associated with the
corresponding id-i
, with let*
, each
exp-i
is evaluated and the result associated with the
corresponding id-i
before starting on the
evaluation of the exp-i+1
. In effect, let*
is
equivalent to:
id-1
in
exp-2
will evaluate to the result of exp-1
.
Here are some examples to help illustrate the difference:
let
by
let*
and the result is the same as it was before. However, if
we introduce a binding of ticks-per-second
to the value
5
, this affects the value of y
. In the third
example, we replace the let*
of the second example, then the
initial value of y
is that of ticks-per-second
in the enclosing lexical scope of the let
expression and the
result is that we got in the previous set of examples.