From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: Re: Elisp lexical-let Date: Fri, 24 Jul 2009 00:39:01 +0200 Message-ID: References: <4A661B73.4090706@domob.eu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1248388770 19002 80.91.229.12 (23 Jul 2009 22:39:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 23 Jul 2009 22:39:30 +0000 (UTC) Cc: Ken Raeburn , guile-devel To: Daniel Kraft Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Jul 24 00:39:23 2009 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MU6wb-00017U-6U for guile-devel@m.gmane.org; Fri, 24 Jul 2009 00:39:21 +0200 Original-Received: from localhost ([127.0.0.1]:55517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MU6wa-0008LU-LU for guile-devel@m.gmane.org; Thu, 23 Jul 2009 18:39:20 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MU6wV-0008LP-2C for guile-devel@gnu.org; Thu, 23 Jul 2009 18:39:15 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MU6wQ-0008Ju-Cj for guile-devel@gnu.org; Thu, 23 Jul 2009 18:39:14 -0400 Original-Received: from [199.232.76.173] (port=55902 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MU6wQ-0008Jl-62 for guile-devel@gnu.org; Thu, 23 Jul 2009 18:39:10 -0400 Original-Received: from a-pb-sasl-sd.pobox.com ([64.74.157.62]:48552 helo=sasl.smtp.pobox.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MU6wP-0000Vg-I1 for guile-devel@gnu.org; Thu, 23 Jul 2009 18:39:09 -0400 Original-Received: from localhost.localdomain (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 5F1E6FD63; Thu, 23 Jul 2009 18:39:09 -0400 (EDT) Original-Received: from unquote (unknown [81.38.186.175]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTPSA id 24E71FD62; Thu, 23 Jul 2009 18:39:05 -0400 (EDT) In-Reply-To: <4A661B73.4090706@domob.eu> (Daniel Kraft's message of "Tue, 21 Jul 2009 21:48:03 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux) X-Pobox-Relay-ID: A2F9C9A4-77D9-11DE-B81D-AEF1826986A2-02397024!a-pb-sasl-sd.pobox.com X-detected-operating-system: by monty-python.gnu.org: Solaris 10 (beta) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:8951 Archived-At: On Tue 21 Jul 2009 21:48, Daniel Kraft writes: > (defvar x 1) > (defun foo () x) > (lexical-let ((x 2)) > x ; -> 2 > (foo) ; -> 1 > (setq x 3) > x ; -> 3 > (foo) ; -> 1 > (let ((x 4)) > x ; -> 4? > (foo) ; -> 4 > (setq x 5) > x ; -> 5 > (foo) ; -> 5 > ) ; end the let > x ; -> 3? > (foo) ; -> 4 > ) > x ; -> 4 > (foo) ; -> 4 It's actually fairly simple, imo. Alpha-equivalence says that (lexical-let ((x a)) x) is the same as (lexical-let ((y a)) y). (Note that this lexical-let corresponds to Scheme's let.) So your program is the same as: > (lexical-let ((y 2)) > y ; -> 2 > (foo) ; -> 1 > (setq y 3) > y ; -> 3 > (foo) ; -> 1 > (let ((x 4)) > x ; -> 4? > (foo) ; -> 4 > (setq x 5) > x ; -> 5 > (foo) ; -> 5 > ) ; end the let > y ; -> 3? > (foo) ; -> 4 > ) > x ; -> 4 > (foo) ; -> 4 I haven't reviewed your compiler yet, and for that I apologize. But. You need to make sure that when you compile, you build up a compile-time environment, mapping symbols to locations -- if a variable is free, lexically bound, or dynamically bound. When your compiler sees a lexical binding, replace that identifier with a gensym, and add an entry to your compile-time environment to map that identifier to that lexical gensym. That way you will effectively be processing my example, which is equivalent to yours, but perhaps clearer because the names have been uniquified. Then your problems go away. Peace, Andy -- http://wingolog.org/