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. The execution of the bindings will occur from the first to the last binding. 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.
(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))) ; prints and returns 6
Note:
(let* (a b) ... )
can be understood as:
(let (a) (let (b) ... ))
See the
let*
special form in the