* Should lexical-let use let in the situation lexical-binding is t ?
@ 2012-09-18 10:28 Tomohiro Matsuyama
2012-09-18 12:44 ` Stefan Monnier
0 siblings, 1 reply; 13+ messages in thread
From: Tomohiro Matsuyama @ 2012-09-18 10:28 UTC (permalink / raw)
To: emacs-devel
Hi,
Someone wants cl's lexical-let expand to let in the situation lexical-binding is t.
http://stackoverflow.com/questions/12456479/lexical-scope-in-emacs-compatibility-with-older-emacsen
I'm not sure that is valid, but if so, I think we should modify lexical-let to improve performance.
Regards,
Tomohiro
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Should lexical-let use let in the situation lexical-binding is t ?
2012-09-18 10:28 Should lexical-let use let in the situation lexical-binding is t ? Tomohiro Matsuyama
@ 2012-09-18 12:44 ` Stefan Monnier
2012-09-18 22:42 ` Richard Stallman
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Stefan Monnier @ 2012-09-18 12:44 UTC (permalink / raw)
To: Tomohiro Matsuyama; +Cc: emacs-devel
> 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
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Should lexical-let use let in the situation lexical-binding is t ?
2012-09-18 12:44 ` Stefan Monnier
@ 2012-09-18 22:42 ` Richard Stallman
2012-09-19 0:41 ` Stefan Monnier
2012-09-19 1:20 ` Sam Steingold
2012-09-21 18:18 ` Tomohiro Matsuyama
2 siblings, 1 reply; 13+ messages in thread
From: Richard Stallman @ 2012-09-18 22:42 UTC (permalink / raw)
To: Stefan Monnier; +Cc: tomo, emacs-devel
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)
Is it really a sensible thing to make a lexical binding for a variable
that is normally dynamic?
--
Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
USA
www.fsf.org www.gnu.org
Skype: No way! That's nonfree (freedom-denying) software.
Use Ekiga or an ordinary phone call
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Should lexical-let use let in the situation lexical-binding is t ?
2012-09-18 22:42 ` Richard Stallman
@ 2012-09-19 0:41 ` Stefan Monnier
2012-09-19 14:12 ` Richard Stallman
0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2012-09-19 0:41 UTC (permalink / raw)
To: rms; +Cc: tomo, emacs-devel
> 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)
> Is it really a sensible thing to make a lexical binding for a variable
> that is normally dynamic?
We don't need to answer this question, because the difference between
`let' and `lexical-let' in this respect is more likely to be accidental.
This said, there can be good reasons to force a lexical binding, when
you fear that the code might be run in a context where the variable
might happen to be defvar'd.
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Should lexical-let use let in the situation lexical-binding is t ?
2012-09-18 12:44 ` Stefan Monnier
2012-09-18 22:42 ` Richard Stallman
@ 2012-09-19 1:20 ` Sam Steingold
2012-09-19 7:43 ` Nix
2012-09-21 18:18 ` Tomohiro Matsuyama
2 siblings, 1 reply; 13+ messages in thread
From: Sam Steingold @ 2012-09-19 1:20 UTC (permalink / raw)
To: emacs-devel
> * Stefan Monnier <zbaavre@veb.hzbagerny.pn> [2012-09-18 08:44:39 -0400]:
>
> As mentioned in my reply there, the two aren't quite compatible
> (because (lexical-let ((tab-width 4)) foo) will be a lexical binding,
are you seriously saying that lexical-let ignores defvar?!
--
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://www.PetitionOnline.com/tap12009/ http://ffii.org
http://mideasttruth.com http://memri.org http://palestinefacts.org
The software said it requires Windows 3.1 or better, so I installed Linux.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Should lexical-let use let in the situation lexical-binding is t ?
2012-09-19 1:20 ` Sam Steingold
@ 2012-09-19 7:43 ` Nix
0 siblings, 0 replies; 13+ messages in thread
From: Nix @ 2012-09-19 7:43 UTC (permalink / raw)
To: sds; +Cc: emacs-devel
On 19 Sep 2012, Sam Steingold uttered the following:
>> * Stefan Monnier <zbaavre@veb.hzbagerny.pn> [2012-09-18 08:44:39 -0400]:
>>
>> As mentioned in my reply there, the two aren't quite compatible
>> (because (lexical-let ((tab-width 4)) foo) will be a lexical binding,
>
> are you seriously saying that lexical-let ignores defvar?!
If it had suddenly changed to make dynamic bindings of defvarred
variables, that might well have broken existing code. lexical-let
is a lot older than native support for lexical binding.
--
NULL && (void)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Should lexical-let use let in the situation lexical-binding is t ?
2012-09-19 0:41 ` Stefan Monnier
@ 2012-09-19 14:12 ` Richard Stallman
2012-09-19 19:01 ` Stefan Monnier
2012-09-19 22:06 ` Sam Steingold
0 siblings, 2 replies; 13+ messages in thread
From: Richard Stallman @ 2012-09-19 14:12 UTC (permalink / raw)
To: Stefan Monnier; +Cc: tomo, emacs-devel
This said, there can be good reasons to force a lexical binding, when
you fear that the code might be run in a context where the variable
might happen to be defvar'd.
I am very skeptical of that claim. It seems to me that if your local
variable is defvar'd by some other code, that is a kind of name
collision and that other code should use a different name which isn't
likely to collide with local variables.
--
Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
USA
www.fsf.org www.gnu.org
Skype: No way! That's nonfree (freedom-denying) software.
Use Ekiga or an ordinary phone call
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Should lexical-let use let in the situation lexical-binding is t ?
2012-09-19 14:12 ` Richard Stallman
@ 2012-09-19 19:01 ` Stefan Monnier
2012-09-19 22:06 ` Sam Steingold
1 sibling, 0 replies; 13+ messages in thread
From: Stefan Monnier @ 2012-09-19 19:01 UTC (permalink / raw)
To: rms; +Cc: tomo, emacs-devel
> This said, there can be good reasons to force a lexical binding, when
> you fear that the code might be run in a context where the variable
> might happen to be defvar'd.
> I am very skeptical of that claim. It seems to me that if your local
> variable is defvar'd by some other code, that is a kind of name
> collision and that other code should use a different name which isn't
> likely to collide with local variables.
Agreed, but you can't always control "other code".
This said, I don't know of any situation where lexical-let was used for
that reason.
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Should lexical-let use let in the situation lexical-binding is t ?
2012-09-19 14:12 ` Richard Stallman
2012-09-19 19:01 ` Stefan Monnier
@ 2012-09-19 22:06 ` Sam Steingold
2012-09-20 3:26 ` Stefan Monnier
1 sibling, 1 reply; 13+ messages in thread
From: Sam Steingold @ 2012-09-19 22:06 UTC (permalink / raw)
To: emacs-devel
> * Richard Stallman <ezf@tah.bet> [2012-09-19 10:12:38 -0400]:
>
> This said, there can be good reasons to force a lexical binding, when
> you fear that the code might be run in a context where the variable
> might happen to be defvar'd.
>
> I am very skeptical of that claim. It seems to me that if your local
> variable is defvar'd by some other code, that is a kind of name
> collision and that other code should use a different name which isn't
> likely to collide with local variables.
yep, that's why Common Lisp recommends defvar'd variables to be named
with "*" around the names.
--
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://ffii.org http://think-israel.org
http://www.memritv.org http://honestreporting.com
There are no answers, only cross references.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Should lexical-let use let in the situation lexical-binding is t ?
2012-09-19 22:06 ` Sam Steingold
@ 2012-09-20 3:26 ` Stefan Monnier
2012-09-20 15:06 ` Sam Steingold
0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2012-09-20 3:26 UTC (permalink / raw)
To: sds; +Cc: emacs-devel
> yep, that's why Common Lisp recommends defvar'd variables to be named
> with "*" around the names.
Yup, and in Elisp we use the "<prefix>-" convention instead (which
was originally introduced to make up for the lack of packages).
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Should lexical-let use let in the situation lexical-binding is t ?
2012-09-20 3:26 ` Stefan Monnier
@ 2012-09-20 15:06 ` Sam Steingold
0 siblings, 0 replies; 13+ messages in thread
From: Sam Steingold @ 2012-09-20 15:06 UTC (permalink / raw)
To: emacs-devel
> * Stefan Monnier <zbaavre@veb.hzbagerny.pn> [2012-09-19 23:26:41 -0400]:
>
>> yep, that's why Common Lisp recommends defvar'd variables to be named
>> with "*" around the names.
>
> Yup, and in Elisp we use the "<prefix>-" convention instead (which
> was originally introduced to make up for the lack of packages).
yep, and `tab-width' is a perfect example of why this is not a good
convention.
--
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://pmw.org.il http://americancensorship.org
http://www.PetitionOnline.com/tap12009/ http://honestreporting.com
There are many reasons not to use Lisp - but no good ones.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Should lexical-let use let in the situation lexical-binding is t ?
2012-09-18 12:44 ` Stefan Monnier
2012-09-18 22:42 ` Richard Stallman
2012-09-19 1:20 ` Sam Steingold
@ 2012-09-21 18:18 ` Tomohiro Matsuyama
2012-09-21 21:18 ` Stefan Monnier
2 siblings, 1 reply; 13+ messages in thread
From: Tomohiro Matsuyama @ 2012-09-21 18:18 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
> 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.
I'm very convinced by your example. Thank you!
By the way, isn't it possible to check if the symbol is declared as special or not by accessing declared_special field of the symbol?
Regards,
Tomohiro
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Should lexical-let use let in the situation lexical-binding is t ?
2012-09-21 18:18 ` Tomohiro Matsuyama
@ 2012-09-21 21:18 ` Stefan Monnier
0 siblings, 0 replies; 13+ messages in thread
From: Stefan Monnier @ 2012-09-21 21:18 UTC (permalink / raw)
To: Tomohiro Matsuyama; +Cc: emacs-devel
> By the way, isn't it possible to check if the symbol is declared as special
> or not by accessing declared_special field of the symbol?
Yes, if the variable has been defvar'd already. But not if the
variable's defvar is in the file we're compiling (and hence hasn't yet
been evaluated), in which case the var will be in
byte-compile-bound-variables instead
(cf. byte-compile-not-lexical-var-p).
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2012-09-21 21:18 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-18 10:28 Should lexical-let use let in the situation lexical-binding is t ? Tomohiro Matsuyama
2012-09-18 12:44 ` Stefan Monnier
2012-09-18 22:42 ` Richard Stallman
2012-09-19 0:41 ` Stefan Monnier
2012-09-19 14:12 ` Richard Stallman
2012-09-19 19:01 ` Stefan Monnier
2012-09-19 22:06 ` Sam Steingold
2012-09-20 3:26 ` Stefan Monnier
2012-09-20 15:06 ` Sam Steingold
2012-09-19 1:20 ` Sam Steingold
2012-09-19 7:43 ` Nix
2012-09-21 18:18 ` Tomohiro Matsuyama
2012-09-21 21:18 ` Stefan Monnier
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.