From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Kraft Newsgroups: gmane.emacs.help Subject: lexical-let detail semantics Date: Mon, 27 Jul 2009 11:50:15 +0200 Message-ID: <4A6D7857.8060001__47372.738706372$1248688568$gmane$org@domob.eu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1248688568 15677 80.91.229.12 (27 Jul 2009 09:56:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 27 Jul 2009 09:56:08 +0000 (UTC) Cc: guile-devel To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 27 11:56:01 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MVMvw-0000KC-He for geh-help-gnu-emacs@m.gmane.org; Mon, 27 Jul 2009 11:55:52 +0200 Original-Received: from localhost ([127.0.0.1]:42027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MVMvv-0007yr-Eg for geh-help-gnu-emacs@m.gmane.org; Mon, 27 Jul 2009 05:55:51 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MVMvN-0007yk-PW for help-gnu-emacs@gnu.org; Mon, 27 Jul 2009 05:55:17 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MVMvI-0007yU-U9 for help-gnu-emacs@gnu.org; Mon, 27 Jul 2009 05:55:17 -0400 Original-Received: from [199.232.76.173] (port=44504 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MVMvI-0007yR-H5 for help-gnu-emacs@gnu.org; Mon, 27 Jul 2009 05:55:12 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:36150 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MVMvH-0000bs-Vq for help-gnu-emacs@gnu.org; Mon, 27 Jul 2009 05:55:12 -0400 Original-Received: from root by ciao.gmane.org with local (Exim 4.43) id 1MVMv8-0001Ns-Qo for help-gnu-emacs@gnu.org; Mon, 27 Jul 2009 09:55:02 +0000 Original-Received: from d86-33-197-36.cust.tele2.at ([86.33.197.36]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 27 Jul 2009 09:55:02 +0000 Original-Received: from d by d86-33-197-36.cust.tele2.at with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 27 Jul 2009 09:55:02 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 61 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: d86-33-197-36.cust.tele2.at User-Agent: Thunderbird 2.0.0.0 (X11/20070425) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:66425 Archived-At: 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