let before, but never used
let* ( let asterisk) mean in elisp?
fyi this one was hard to google because of the asterisk.
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
It means that when there is more than one binding the variables are bound sequentially, so that each can depend on the values bound to those that are bound before it, i.e., those that come before it in the
let (no asterisk), none of the bindings can be assumed to occur before any of the others (the variables could, in principle, be bound in parallel).
(let ((a 42) (b a))...b) can raise an error because it tries to bind
b to the value of
a (at least the particular
a that is bound in this
let) cannot be assumed to have been bound to a value.
[If some other (e.g. global) variable
a is bound to a value, e.g.,
5, then that
let expression would bind its (local)
42 and bind
b to the value of the global
(let* ((a 42) (b a))...b) returns
a gets bound to
42 and then
b gets bound to the value of
See the Elisp manual, node Local Variables.
Update, from @DoMiNeLa10's reminder in a comment:
In addition to the manual, you can also use the help commands. Of all the various ways to "ask Emacs", they are among the first to learn and the most useful.
C-h f let* tells us, succinctly:
Each VALUEFORM can refer to the symbols already bound by this VARLIST.
Though there's nothing wrong with asking here, you would do yourself a favor if you asked Emacs such questions. Just use
C-h i to open the Info browser of manuals, choose the
Elisp manual, and use
i let* to look up
let* in the index (with completion). That takes you directly to the node that covers this.
(And the manual typically covers things better than will be done here, as a lot of time and effort, by thousands of contributors, have gone into getting it right: correct and complete.)
You can also search this site for questions and answers that use tag
let-binding: Just put
[let-binding] in the search field. (I'll do that now, to see if this question is perhaps a duplicate...)
let* is like a recursive
(let* ((var1 VAL1) (var2 VAL2)) ...)
(let ((var1 VAL1)) (let ((var2 VAL2)) ...))
Thereby the usage of capital letters for
VAL2 indicates that those can also be expressions.
let-binding has consequences if
VAL2 depends actually on
var1. The effect is already described in Drew's answer.