Evaluating with a lexical environment

Spiros Bousbouras spibou at gmail.com
Thu Jul 11 18:44:46 UTC 2019


clisp  provides a facility to evaluate a form in a non null lexical
environment. It works as follows

> (let   ((a 1) (b 2))
      (ext:eval-env '(format t "a is ~A  b is ~A~%" a b) (ext:the-environment)))
a is 1  b is 2
NIL


The  clisp  documentation gives
    Macro EXT:THE-ENVIRONMENT. As in Scheme, the macro (EXT:THE-ENVIRONMENT)
    returns the current lexical environment. This works only in interpreted
    code and is not compilable!

    Function (EXT:EVAL-ENV form &OPTIONAL environment). evaluates a form in
    a given lexical environment, just as if the form had been a part of the
    program that the environment came from.

I was wondering if ECL has something analogous or could be added easily.
Looking in the ECL source I saw a  si::eval-with-env  function in file
ecl-16.1.3/src/c/compiler.d .If you do

> (find-symbol "EVAL-WITH-ENV" "SYSTEM")
SI:EVAL-WITH-ENV
:EXTERNAL

which suggests that the function is not just for internal use. But scanning
the documentation , I didn't see it mentioned. I tried

(defmacro env-eval (form &environment env)
    `(ext:eval-with-env ,form (quote ,env)))
ENV-EVAL
> (let ((v 12)) (env-eval '(print v)))
The variable V is unbound.
Broken at EVAL.No restarts available.
Broken at EVAL.


So is there a way to achieve this ?



More information about the ecl-devel mailing list