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")
 > which suggests that the function is not just for internal use. But 
 > 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)))
 >> (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)))
CL-USER> (let ((v 42))
            (eval-with-lexenv-ala-clisp '(print v)))


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

Best regards,

More information about the ecl-devel mailing list