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

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

Re: `pp-eval-expression' behaves strangely under lexical binding


From: Stefan Monnier
Subject: Re: `pp-eval-expression' behaves strangely under lexical binding
Date: Mon, 18 Apr 2016 11:58:09 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

>>> But isn't my question still valid for `symbol-value'?
>> No, whether it's implemented in C or in Lisp is irrelevant.  As soon as
>> you put a symbol into a `quote`, it can't be a reference to a lexical
>> variable any more because the compiler will treat it as data and data
>> cannot refer to lexical variables, only to other data.
>> Dynamically scoped variables are data, on the other hand (they're just
>> a particular field of a symbol object, which is a kind of "struct").
> This short description is very helpful. Could you add some similar wording
> to the elisp manual to help clarify usage of lexical binding ?

I don't really see how/where to put it in the manual, sadly.
If you give me a sample patch, I promise I'll try to improve it ;-)


        Stefan


PS: Another way to look at those issues is from the "α-renaming" point
of view.  A lexical variable's name should have no impact on the code,
in the sense that the compiler should be able to rename it or get rid of
the name (and indeed Emacs's Elisp compiler gets rid of the lexical
variables's names).  So the compiler can take

    (let ((a 1))
      (foo 'a (+ a 1)))

and treat it as if you had written

    (let ((b 1))
      (foo 'a (+ b 1)))

or even

    (let ((<noname> 1))
      (foo 'a (+ <the-last-var-defined> 1)))

But clearly, it can treat it as if you had written

    (let ((b 1))
      (foo 'b (+ b 1)))

[ Unless maybe the compiler is being told that `foo` takes
  a variable-identifier as first argument.  ]

and even less

    (let ((<noname> 1))
      (foo <reference-to-the-last-var-defined> (+ <the-last-var-defined> 1)))

since `foo` now wouldn't even receive a *symbol* any more but some other
kind of object (lexical variables, at run-time, aren't referenced via
symbols at all).


        Stefan




reply via email to

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