From: Kelly Dean <kellydeanch@yahoo.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Is add-to-list supposed to work when lexical-binding is t?
Date: Tue, 11 Jun 2013 17:59:36 -0700 (PDT) [thread overview]
Message-ID: <1370998776.79679.YahooMailClassic@web141104.mail.bf1.yahoo.com> (raw)
Stefan Monnier wrote:
>> I don't see cases where quote-var would fail to do what's intended.
>We can have gv-ref/quote-var/quote-lex/younameit, but what we can't do
>is merge it with quote, because their semantics are incompatible:
> (eq (let ((x 1)) (quote-var x)) (let ((x 1)) (quote-var x)))
>should return nil, whereas
> (eq (let ((x 1)) (quote x)) (let ((x 1)) (quote x)))
>should return t.
True, and that's a good way to explain the difference between a variable and a symbol. On June 5 I wrote, "If overloading quote is a bad idea, then quote-lex should return a reference to the current instance of the given variable regardless of whether it's given a lexical or global variable", which means
(defvar x 1)
(eq (quote-var x) (quote-var x))
should return t. But
(eq (gv-ref x) (gv-ref x))
returns nil, so gv-ref isn't a suitable substitute for quote-var.
I further wrote, "that means in the latter case, it does the same thing as quote", which means I was confusing variables with symbols. :-)
And further, "which means quote-lex can be used instead of quote in all places, except where a symbol needs to be returned despite that symbol also serving as a lexical variable in the same scope, because the symbol will be used as the global variable or as something other than a variable."
Which now I think should be: in order to avoid a type error, quote-var _must_ be used, unless the symbol will be used as something other than a variable. But then there are a couple problems: 1, Lisp can't detect the type error anyway, so what's the point? And 2, if you actually do need to quote a global variable that's shadowed by a lexical variable, there's no way to do it except (quote global-var), yet that's a type error. I suppose the answer to the second problem is: don't shadow the global; use a different name for the lexical.
To solve the first problem, I think set and symbol-value would have to signal an error if given a non-variable symbol, and eq would have to distinguish variables and symbols:
(setq x 1)
(symbol-value (quote-var x)) -> 1
(symbol-value (quote x)) -> type error
(eq (quote x) (quote-var x)) -> type error
which also means symbol-value would more appropriately be called "variable-value", which seems reasonable anyway, since non-variable (well, and non-constant) symbols don't have values.
But it's just an academic argument, since signalling such errors would break everything.
In my previous message I wrote:
>For completeness, either (setq indent-line-function 'my-indent-func) should
>signal a type error, or "'x" should be read as (quote-var x), and (setq
>cursor-type 'bar) should signal a type error
But the type error can't be detected until indent-line-function or cursor-type is used. Oops.
This concludes my public conversation with myself for today.
Your example above explains symbol vs. variable. To explain variable vs. instance:
(defun foo (&optional p_x)
(let ((x))
(if p_x (eq p_x (quote-var x))
(foo (quote-var x)))))
(foo) -> nil
which also means maybe "quote-var" isn't a good name either; "younameit" might be just as good!
Barry Margolin wrote:
>> When eval sees the symbol x, and is going to interpret it as a lexical
>> variable, as it does in your example, it looks up, in the current lexical
>> environment
>Since eval is just an ordinary function, it doesn't have access to the
>lexical environment.
The elisp manual, section 11.9.3 Lexical Binding, says:
"When the Lisp evaluator wants the
current value of a variable, it looks first in the lexical environment;
if the variable is not specified in there, it looks in the symbol's
value cell, where the dynamic value is stored."
Did I miss something?
next reply other threads:[~2013-06-12 0:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-12 0:59 Kelly Dean [this message]
[not found] <mailman.1450.1370998793.22516.help-gnu-emacs@gnu.org>
2013-06-13 14:57 ` Is add-to-list supposed to work when lexical-binding is t? Stefan Monnier
[not found] <mailman.1311.1370828650.22516.help-gnu-emacs@gnu.org>
2013-06-10 5:12 ` Barry Margolin
-- strict thread matches above, loose matches on Subject: below --
2013-06-10 1:43 Kelly Dean
2013-06-10 7:56 ` Stefan Monnier
2013-06-05 23:12 Kelly Dean
2013-06-06 0:42 ` Stefan Monnier
2013-06-04 0:42 Kelly Dean
2013-06-04 1:49 ` Stefan Monnier
2013-06-04 15:24 ` PJ Weisberg
2013-06-05 2:41 ` Stefan Monnier
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1370998776.79679.YahooMailClassic@web141104.mail.bf1.yahoo.com \
--to=kellydeanch@yahoo.com \
--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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).