Den søn. 7. jun. 2020 kl. 14.09 skrev Siyuan Chen <[email protected]>:

Unfortunately, this code doesn't work, because it lacks two functions,
> `get-current-env` and `extends-env`.
>

These are not available since static lexical scope makes it possible for
the compiler to determine where
a variable is stored at compile time. Therefore an explicit environment is
not needed.
(See "early binding" vs "late binding").


> Is there any way to work around this issue?
>


> I have searched Racket's document. Racket has namespaces that are very
> similar to the environment here.
>
> But it seems that `current-namespace` can not get binding (e.g. Just) and
> `namespace-set-variable-value!` is a mutable function which is not suitable
> as well.
>

Namespaces are "environment-like" but contain only top-level variables.

Could someone give me some advice?
> Or we can modify the code above to make it work in Racket.
>

Since this for educational/fun use and not practical, I suggest using a
Scheme interpreter where the environments
are explicit.  Then you can easily add `get-current-env` and `extends-env`
yourself.

One option is the interpreter page LiSP (Lisp in Small Pieces) where an
interpreter for fexprs is discussed
with full working code.

/Jens Axel
https://racket-stories.com

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgwBO%2BMG6SH66mHM_-LTsxpWTBsTu-%3DKSQ-skwjmUQvBOA%40mail.gmail.com.

Reply via email to