My problem is the next, i try to evaluate a list with some vars using a let to asign values to this vars
if i do (def a (list * 'x 'y))
and (let [x 3 y 3] (eval a))
I have a
CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context, compiling:(NO_SOURCE_PATH:6)
but if I run
(def x 4) (def y 4)
and (eval a)
i have a 16, anyway if I run again (let [x 3 y 3] (eval a))
again I have 16,
exist a method to binding the x and y correctly and eval the list?
ty!
let
defines lexically scoped bindings that are not accessible from the body of the eval function. This is no different than any other function. However, the bindings created with def
are accessible because they are namespace global. All functions have access to namespace global variables, as long as they are public.
(def ^:dynamic x 4) (def ^:dynamic y 4)
user=> (binding [x 3 y 3] (eval a))
9
user=> (eval a)
16
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With