emacs-devel
[Top][All Lists]
Advanced

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

Re: Should lexical-let use let in the situation lexical-binding is t ?


From: Stefan Monnier
Subject: Re: Should lexical-let use let in the situation lexical-binding is t ?
Date: Tue, 18 Sep 2012 08:44:39 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux)

> I'm not sure that is valid, but if so, I think we should modify
> lexical-let to improve performance.

As mentioned in my reply there, the two aren't quite compatible (because
(lexical-let ((tab-width 4)) foo) will be a lexical binding, whereas
(let ((tab-width 4)) foo) will be a dynamic binding) so we could do
that, but only after checking that the lexical-let-bound variable is not
defvar'd, and this requires checking byte-compile-bound-variables, so it's
rather ugly to do from a macro.

Furthermore, it can be non-trivial for the macro to figure out whether
it's really called in a lexical-binding context or not and whether
byte-compile-bound-variables is relevant, since the macro call being
expanded might come from code being executed during compilation
(e.g. loaded via a `require') rather than from code being compiled.

I've recently tightened a bit the way lexical-binding is set, so that
testing `lexical-binding' in a macro should now be fairly accurate (the
C code rebinds lexical-binding during macro-calls to reflect whether the
macro is expanded in a lexical-binding context or not, rather than
leaving the variable's value determined by the current-buffer's local
value), but testing byte-compile-bound-variables is likely to
be unreliable.

IOW, it's OK for the OP to use such a macro himself because he hopefully
won't fall into those traps in those places where he uses it, but if we
do right in lexical-let so that it applies to all uses of lexical-let,
there's a good chance we could bump into those problems, and they may be
very difficult to track down.


        Stefan



reply via email to

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