From: David Richter
Subject: Re: Gnu Extension Lang technical question - translating lisp to scheme.
Date: 
Message-ID: <38onfe$h61@larry.rice.edu>
In article <·····················@sunset.huji.ac.il>, 
·······@sunset.huji.ac.il (Harvey J. Stein) writes:
|> Regarding RMS's idea of translating various languages to scheme, I'm
|> curious to know how the elisp to scheme conversion would work.  I
|> can't see how it could be straight forward, given that elisp is
|> dynamically scoped & scheme is lexically scoped.  From what I've
|> heard, one needs to make environments first class in scheme to be able
|> to achieve dynamic scoping on demand, but doing so severely hampers
|> the ability of compilers to produce fast code.

Actually, that is very simple, given that elisp does not have 
first class continuations.  Simply implement dynamic-wind.  (I believe
this is a r4rs thing, but in any case implementations abound.)  Then
implement dynamic variables as fluid-lets (as in Chez) as a macro
over dynamic-wind, eg:

(lambda-dynamic (x) M)  --> 
		(lambda-lexical (y)
		  (fluid-let ([x y]) M))  where y is not free in M

A definition for fluid-let of 1 variable is as follows.
(extend-syntax (fluid-let)
  [(fluid-let ([x v]) B1 Bs ...)
   (symbol? 'x)
   (with ([y (gensym)])
     (dynamic-wind
       (lambda () (set! y x) (set! x v))
       (lambda () B1 Bs ...)
       (lambda () (set! x y))))])

The general case is obvious, and can easily be written to use only
one dynamic-wind.

David