Evaluating with a lexical environment

Daniel KochmaƄski daniel at turtleware.eu
Thu Jul 11 19:39:34 UTC 2019


Hello Spiros,

 > I was wondering if ECL has something analogous or could be added easily.
no such interfaces are present currently in ECL. Even with bytecompiler 
code is not interpreted but always minimally compiled.

 > 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.
symbols in package system are part of ecl internals (this is 
documented), they are not part of the api. Only symbols reexported to 
ext are somewhat stable.

 > 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 ?
 >
eval-with-evn accepts the lexical environment while environment put 
there by defmacro is something else. You may use a hack, but I do not 
guarantee it will work in all scenarios:

CL-USER> (defmacro eval-with-lexenv-ala-clisp (form)
            `(let ((lexenv (nth-value 1 (function-lambda-expression 
(lambda ())))))
               (si:eval-with-env ,form lexenv)))
EVAL-WITH-LEXENV-ALA-CLISP
CL-USER> (let ((v 42))
            (eval-with-lexenv-ala-clisp '(print v)))

42
42

Most notably this *won't* work in normally compiled code.

Best regards,
Daniel



More information about the ecl-devel mailing list