0
votes

How to evaluate some lisp code using eval in not null lexical environment ? I need this feature for proper interpolation functionality.

1
It's not possible, however you should perhaps change your question to the actual problem rather than your problems regarding your chosen solution since this smells like a XY problem. - Sylwester
Ok, thanks, actually, I just needed to be sure there's no way how to do it. Actually, I decided to send hash table with values instead of accessing environment. - dev1223

1 Answers

1
votes

If you model your environment as bindings like those found in let:

((x 3) (y 2))

... then you can evaluate any form f with those bindings in place, like so:

(eval `(let ,e ,f))

This is the simplest case, but you can easily convert your data to fit this syntax. You can also bind functions, macros, etc. if needed.

Note that if you need values at runtime, then maybe dynamic bindings are better. You can use hash-tables, etc. but note that there is also the lesser-known PROGV special operator:

Among other things, progv is useful when writing interpreters for languages embedded in Lisp; it provides a handle on the mechanism for binding dynamic variables.