all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Daniel Kraft <d@domob.eu>
To: help-gnu-emacs@gnu.org
Subject: Re: lexical-let detail semantics
Date: Mon, 27 Jul 2009 16:44:02 +0200	[thread overview]
Message-ID: <4A6DBD32.9060100@domob.eu> (raw)
In-Reply-To: <7c63deuuyr.fsf@pbourguignon.anevia.com>

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




  reply	other threads:[~2009-07-27 14:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.3248.1248688520.2239.help-gnu-emacs@gnu.org>
2009-07-27 10:50 ` lexical-let detail semantics A.Politz
2009-07-27 12:09   ` Daniel Kraft
2009-07-27 13:16 ` Pascal J. Bourguignon
2009-07-27 14:44   ` Daniel Kraft [this message]
     [not found]   ` <mailman.3293.1248739037.2239.help-gnu-emacs@gnu.org>
2009-07-28  0:48     ` Pascal J. Bourguignon
2009-07-27  9:50 Daniel Kraft

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A6DBD32.9060100@domob.eu \
    --to=d@domob.eu \
    --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.
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.