[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Elisp lexical-let
From: |
Andy Wingo |
Subject: |
Re: Elisp lexical-let |
Date: |
Fri, 24 Jul 2009 00:39:01 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux) |
On Tue 21 Jul 2009 21:48, Daniel Kraft <address@hidden> 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/
- Re: Elisp lexical-let, (continued)
- Re: Elisp lexical-let, Daniel Kraft, 2009/07/23
- Re: Elisp lexical-let, Marijn Schouten (hkBst), 2009/07/24
- Re: Elisp lexical-let, Ken Raeburn, 2009/07/22
- Re: Elisp lexical-let, Daniel Kraft, 2009/07/23
- Re: Elisp lexical-let, Andy Wingo, 2009/07/23
- Re: Elisp lexical-let, Daniel Kraft, 2009/07/24
- Re: Elisp lexical-let, Andy Wingo, 2009/07/23
Re: Elisp lexical-let,
Andy Wingo <=