Hi Andy,
thanks for the clarifications!
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
Yes of course, my main question was how the inner let is handled, and
what dynamic values x will attain (the results of (foo)) -- and here's
this funny stuff that the inner let will be like lexical-let for those
variables already lexically bound.
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.
This is how I was thinking about implementing the lexical-let semantics.
To give more details:
I want to keep track of identifiers that are lexically bound in the
current scope while compiling as well as to what gensym they are, and
then instead of the fluid-ref's just reference/set this
gensym-identifier when I come across an access. It seems this is
exactly what you describe above :)
So, that's it with regards to messages from me :D Thanks for all your
comments again,
Daniel
--
Done: Arc-Bar-Cav-Ran-Rog-Sam-Tou-Val-Wiz
To go: Hea-Kni-Mon-Pri