2.9 Local Binding: let, let*, letrec, ...
Local Binding in Guide: PLT Scheme introduces local binding.
Examples: | ||||
> (let ([x 5]) x) | ||||
5 | ||||
| ||||
(5 2) |
The second form evaluates the init-exprs; the resulting values become arguments in an application of a procedure (lambda (id ) body ), where proc-id is bound within the bodys to the procedure itself.
Example: | ||||
| ||||
3628800 |
(let* ([id val-expr] ) body ) |
Example: | |||
| |||
(2 1) |
(letrec ([id val-expr] ) body ) |
Example: | |||||||
| |||||||
#t |
(let-values ([(id ) val-expr] ) body ) |
Example: | ||
| ||
(1 3) |
(let*-values ([(id ) val-expr] ) body ) |
Example: | |||
| |||
(1 3) |
(letrec-values ([(id ) val-expr] ) body ) |
Example: | |||||||||
| |||||||||
#t |
(let-syntax ([id trans-expr] ) body ) |
See also splicing-let-syntax.
Creates a transformer binding (see Transformer Bindings) of each id with the value of trans-expr, which is an expression at phase level 1 relative to the surrounding context. (See Identifiers and Binding for information on phase levels.)
The evaluation of each trans-expr is parameterized to set current-namespace to a namespace that shares bindings and variables with the namespace being used to expand the let-syntax form, except that its base phase is one greater.
Each id is bound in the bodys, and not in other trans-exprs.
(letrec-syntax ([id trans-expr] ) body ) |
See also splicing-letrec-syntax.
Like let-syntax, except that each id is also bound within all trans-exprs.
(let-syntaxes ([(id ) trans-expr] ) body ) |
See also splicing-let-syntaxes.
Like let-syntax, but each trans-expr must produce as many values as corresponding ids, each of which is bound to the corresponding value.
(letrec-syntaxes ([(id ) trans-expr] ) body ) |
See also splicing-letrec-syntaxes.
Like let-syntax, except that each id is also bound within all trans-exprs.
|
See also local, which supports local bindings with define, define-syntax, and more.