Skip to content

Instantly share code, notes, and snippets.

@tonini
Created April 30, 2013 21:07
Show Gist options
  • Save tonini/5491958 to your computer and use it in GitHub Desktop.
Save tonini/5491958 to your computer and use it in GitHub Desktop.
Special Form: let (bindings...) forms...
This special form binds variables according to bindings and then evaluates all of the forms in textual order. The let-form returns the value of the last form in forms.
Each of the bindings is either (i) a symbol, in which case that symbol is bound to nil; or (ii) a list of the form (symbol value-form), in which case symbol is bound to the result of evaluating value-form. If value-form is omitted, nil is used.
All of the value-forms in bindings are evaluated in the order they appear and before any of the symbols are bound. Here is an example of this: Z is bound to the old value of Y, which is 2, not the new value, 1.
(setq Y 2)
=> 2
(let ((Y 1)
(Z Y))
(list Y Z))
=> (1 2)
Special Form: let* (bindings...) forms...
This special form is like let, but it binds each variable right after computing its local value, before computing the local value for the next variable. Therefore, an expression in bindings can reasonably refer to the preceding symbols bound in this let* form. Compare the following example with the example above for let.
(setq Y 2)
=> 2
(let* ((Y 1)
(Z Y)) ; Use the just-established value of Y.
(list Y Z))
=> (1 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment