Julien a écrit : > Here is a quick newbie question. > > (def test1 "test1") > (let [test2 "test2"] > (eval (read-string "(println test1)")) > (eval (read-string "(println test2)")) > ) > > -output > test1 > 1:1 user=> java.lang.Exception: Unable to resolve symbol: test2 in > this context (testLet.clj:0) > > How could (read-string "") access to a binding local to a form? >
read-string doesn't care about the context, it reads a string and returns the data structure represented by this string, it knows nothing about which vars are interned in which namespace, which symbols denote locals etc. This is the job of eval and eval does not have access to locals because it's just a regular function. I mean, when you write (let [test2 "test2"] (foobar)) the implementation of foobar can not refer to test2 since test2 is defined locally and foobar was defined elsewhere. You can cheat and use a function to explicitely pass arguments: user=> (list 'fn '[test2] (read-string "(println test2)")) (fn [test2] (println test2)) user=> (eval (list 'fn '[test2] (read-string "(println test2)"))) #<user$eval__4338$fn__4340 user$eval__4338$fn__4...@68097d> user=> (*1 "test2") test2 nil Whate are you trying to achieve? hth, Christophe -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (en) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---