Description Usage Arguments Details Value Note Examples
These functions provide the let, let* and letrec block-scope operators from Scheme. All three of them create temporary variables with specified values, successively evaluate provided body expressions, and return the value of the last expression.
1 2 3 4 5 |
bindings |
A list whose elements are themselves two element lists: the first element of each is a symbol, the second the value the symbol should be bound to in the environment for evaluating the body statements. |
... |
Body statements. |
All three forms are syntactically identical:
.(LET_OP, .(.(variable, init) ...), expr, expr ...)
where LET_OP is let
, let.star
or letrec
.
They differ in the scope in which the temporary bindings (of names to init expressions' values) exist:
let computes the init expressions before creating any bindings.
let.star creates the bindings, and in the process evaluates the init expressions, sequentially left to right, so that earlier bindings are in scope for evaluating later init expressions.
letrec evaluates all init expressions simultaneously, with all bindings in scope during evaluation. (The init expressions can therefore be mutually recursive.)
The result of evaluating the final body expression.
R, unlike Scheme, does not have a notion of variable definition separate from assignment. So the init expressions are mandatory here, whereas in Scheme it is possible to create uninitialized variables in the scope of the body block.
The let, let.star and letrec functions take arguments in a way that seems
natural in prefix
notation, but makes for odd-looking calls
in the usual infix form. Calling them "directly" - i.e., other than through
prefix code and SchemeR() or infix() - is not recommended.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | schemeR::schemeR({
.(let, .(.(i, 3),
.(foo, 5)),
.(`==`, i, .(`-`, foo, 2)))
}, pkg=TRUE) == TRUE
schemeR::schemeR({
.(let.star, .(.(i, 3), .(foo, 5)),
.(`==`, i,
.(`-`, foo, 2)))
}, pkg=TRUE) == TRUE
schemeR::schemeR({
.(letrec, .(.(i, 3), .(foo, 5)),
.(`==`, i,
.(`-`, foo, 2)))
}, pkg=TRUE) == TRUE
schemeR::schemeR({
.(letrec, .(.(i, 3),
.(foo, .(lambda, .(n), .(`+`, n, 1)))),
.(`==`, i, .(foo, 2)))
}, pkg=TRUE) == TRUE
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.