XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

let


Type:   -   special form (fsubr)
Source:   -   xlcont.c

Syntax

(let ([binding ... ]) expr ... )
binding - a variable binding which is one of the forms:
symbol
(symbol init-expr)
symbol - a symbol
init-expr - an initialization expression for symbol
expr - an expression
returns - the value of the last expression

Description

The 'let' special form is basically a local block construct that contains symbols [with optional initializations] and a block of code [expressions] to evaluate. The first form after the 'let' is the 'binding' form. It contains a series of 'symbols' or 'bindings'. The 'binding' is a 'symbol' followed by an initialization expression 'init-expr'. If there is no 'init-expr', the 'symbol' will be initialized to NIL. There is no specification as to the order of execution of the bindings. The 'let' form will go through and create and initialize the symbols and then sequentially execute the 'exprs'. The value of the last 'expr' evaluated is returned. When the 'let' is finished execution, the 'symbols' that were defined will no longer exist or retain their values.

Examples

(let (x y z)                      ; LET with local vars
  (print x) (print y) (print z))  ;   prints   NIL NIL NIL

(let ((a 1) (b 2) (c 3))          ; LET with local vars & init
  (print (+ a b c)))              ;   prints and returns 6

(let ((a 1) (b 2) (c (+ a b)))    ; LET with local vars & init
  (print (+ a b c)))              ;   error: unbound variable - A

Note: to make the last example work you need the let* special form.

See the let special form in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next