unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Daniel Kraft <d@domob.eu>
To: help-gnu-emacs@gnu.org
Cc: guile-devel <guile-devel@gnu.org>
Subject: lexical-let detail semantics
Date: Mon, 27 Jul 2009 11:50:15 +0200	[thread overview]
Message-ID: <4A6D7857.8060001__47372.738706372$1248688568$gmane$org@domob.eu> (raw)

Hi,

I'm working on an implementation of elisp for GNU Guile, and want to 
include the lexical-let construct from the Common Lisp Extensions of 
elisp.  There are some details of its semantics I'm not sure about and 
that are not clarified in the documentation of lexical-let, so I had to 
do some experiments.  Here are two questions that came up during these 
where I'd love to hear comments from regular elisp users:


1) let within lexical-let:

(setq a 1)
(defun dyna () a)
(lexical-let ((a 2))
   (let ((a 3))
     (print (dyna))))
   => 1

My first thought was that a let within the lexical scope of another 
lexical-let would revert the symbols to dynamic scoping again, but it 
seems that let behaves just as if it was lexical-let for symbols already 
lexically bound.

Is this 'expected behaviour' or something 'by chance'?  Do you think it 
is necessary for compatibility with (most) existing code to mimic this 
behaviour or would it be ok for the code above to print 3?

In contrast, the code:

(setq a 1)
(defun dyna () a)
(lexical-let ((a 2))
   ((lambda (a)
      (print (dyna))) 3))
   => 3

does indeed revert a to dynamic binding...  This seems somewhat 
inconsistent to me (although of course argument-lists and let's are not 
really the same thing).


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?

Thank you very much for your help!
Daniel





             reply	other threads:[~2009-07-27  9:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-27  9:50 Daniel Kraft [this message]
     [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
     [not found]   ` <mailman.3293.1248739037.2239.help-gnu-emacs@gnu.org>
2009-07-28  0:48     ` Pascal J. Bourguignon

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='4A6D7857.8060001__47372.738706372$1248688568$gmane$org@domob.eu' \
    --to=d@domob.eu \
    --cc=guile-devel@gnu.org \
    --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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).