On Tue 21 Jul 2009 21:48, Daniel Kraft <d...@domob.eu> 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/