help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Understanding the "let" construct and the setting of variables


From: Drew Adams
Subject: RE: Understanding the "let" construct and the setting of variables
Date: Thu, 17 Dec 2020 08:55:52 -0800 (PST)

> Yes, indeed. Variables bound with `let` or `let*` only exist inside the
> `let`.
> So as soon as you put the closing parenthesis matching the opening
> parenthesis
> directly before the `let`, the variables go out of scope and no longer exist.
> (There are actually a couple of subtleties involved that make this statement
> less than universally true, but those issues shouldn't concern a beginner.)

This is not true of dynamically scoped, i.e. "special"
vars.

What is correct to say is that the let _binding_ of the
variable no longer exists, not that the variable itself
no longer exists.

In the case of a dynamic variable, it continues to exist.
And its binding from the let continues to exist as long
as the code in the let body is executing.

[Yes, some people will consider a let binding to create
a _new_ variable.  In that sense you can say that that
var ceases to exist.  But IMO that isn't as clear to
users as it is to distinguish the binding from the var.
And even if you use the words that way, you still need
to point out that the var continues to exist as long as
the code within the let body is executing (when the
binding is for a dynamic var).]

The best explanation of let binding in Elisp is in the
Common Lisp doc, IMO.  In particular, CLTL2's explanation
of dynamic and lexical binding is quite clear.  It applies
equally to Elisp.

https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node43.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]