Structural Informatics Group (SIG) logo
Home | Projects | Demos | Downloads | Publications | Local Info | About Us | New site
Go to the first, previous, next, last section, table of contents.

let

let

type: special form (fsubr)
location: built-in
source file: xlcont.c
Common LISP compatible: yes
supported on: all machines

SYNTAX

(let  ( [ <binding> ... ]  ) <expr> ... )
        <binding>       -       a variable binding which is of the form
                                <symbol>     or    ( <symbol> <init-expr> )
        <symbol>        -       a symbol
        <init-expr>     -       an initialization expression for <symbol>
        <expr>          -       an 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 <symbol>'s or <binding>'s. 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 <expr>'s. The value of the last <expr> evaluated is returned. When the LET is finished execution, the <symbol>'s 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
                                        ;  because (+ A B) init code
                                        ;  depends on vars A and B
                                        ;  which haven't been created
                                        ;  yet - because of ordering


Go to the first, previous, next, last section, table of contents.