[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: lexical-let detail semantics
From: |
Daniel Kraft |
Subject: |
Re: lexical-let detail semantics |
Date: |
Mon, 27 Jul 2009 16:44:02 +0200 |
User-agent: |
Thunderbird 2.0.0.0 (X11/20070425) |
Hi Pascal,
thanks for your nice answers!
Pascal J. Bourguignon wrote:
You can avoid the problem by putting the dynaminc bindings outside of
reach of lexical-let:
(defun call-dyna ()
(let ((a 3)) (print (dyna))))
(lexical-let ((a 2))
(call-dyna))
prints: 3
--> 3
Notice also that in languages that have both special variables and
lexical variables, it is found worthwhile to keep them in separate
name spaces. In ISO-LISP, this is done with the (dynamic var) form
for special variables. In Common Lisp it's done with the *earmuff*
convention.
That's true of course (and good advice), but unfortunatly I'm working on
another implementation of elisp which should include lexical-let
natively (instead of being a user) and thus I'm forced to care about
such special cases, too.
You may report the bug to the maintainers, but I'm not sure it's
worthwhile. If you want a real language, perhaps you could use
emacs-cl? http://www.lisp.se/emacs-cl/
Hm... My main point was whether this is expected behaviour I should
mimic in my implementation, but I take your response that you would
prefer to have my implementation behave differently (like what I
described as my expectation)?
Do you think this would lead to compatibility problems with existing code?
2) Closures:
I'm happy that lexical-let works well to build closures (and in fact
it seems that this is the main intention for lexical-let at all);
however this code does not work as expected:
(setq a 1)
(lexical-let ((a 2))
((lambda () (print a))))
=> 1
I don't know why, but it seems that calling a closure directly fails,
while storing it and calling it later succeeds (as in the examples at
http://www.delorie.com/gnu/docs/emacs/cl_21.html for instance). Is
this a bug or again something expected? If the latter, what's the
exact rationale and semantics then?
I guess you have a bug in your version. Mine works ok.
Again, the macroexpansion explains what lexical-let does in this case:
Yes, that's right; I checked with a current development version of emacs
and there it works as expected.
Yours,
Daniel