From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: add-to-list with lexical variables
Date: Sat, 08 Jun 2013 16:34:49 -0400 [thread overview]
Message-ID: <jwv7gi4mjl5.fsf-monnier+gmane.emacs.help@gnu.org> (raw)
In-Reply-To: 874nd8hbox.fsf@gmail.com
>>> 1. when I set `lexical-binding' to t and byte-compile the file, it
>>> would report this error:
>>>
>>> add-to-list cannot use lexical var `env-list'
add-to-list is a function, and functions have access to the
dynamically-bound vars of its caller, but not to the lexically-bound
vars of its caller.
The warning was added because add-to-list is a frequent use-case where
Elisp code presumes dynamic binding.
>>> 2. And when I using `lexical-let*' instead, there would be an warning:
>>>
>>> Warning: assignment to free variable `env-list'
lexical-let is an old way to get lexical binding. It was added long
before add-to-list was invented, and it was only used at those few
places where people really wanted lexical binding, and those people
generally knew that add-to-list couldn't possibly work there, so the use
of add-to-list on a var bound with lexical-let was so rare that it
didn't occur to anybody to try and provide an ad-hoc check and warning.
instead it just notices that the call to `add-to-list' uses a (dynamic)
variable `env-list' which is not declared (i.e. is "free").
> However I still don't know the difference `lexical-binding' and
> `lexical-let' brings. Are there some authoritative introductions/tutorials?
lexical-let is an old hack made obsolete by lexical-binding.
Stefan
next prev parent reply other threads:[~2013-06-08 20:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-08 12:39 add-to-list with lexical variables Hongxu Chen
2013-06-08 14:00 ` Pascal J. Bourguignon
2013-06-08 15:19 ` Hongxu Chen
2013-06-08 20:34 ` Stefan Monnier [this message]
[not found] ` <mailman.1222.1370704797.22516.help-gnu-emacs@gnu.org>
2013-06-08 17:08 ` Pascal J. Bourguignon
2013-06-09 3:18 ` Hongxu Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv7gi4mjl5.fsf-monnier+gmane.emacs.help@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.