On Mon, Jun 20, 2011 at 4:45 PM, Jonathan Fischer Friberg
<[email protected]> wrote:
> user=> (def a (fn [] "outside a"))
> #'user/a
> user=> (let [a (fn [] "inside a")] (load-string "(a)"))
> "outside a"
> user=> (let [a (fn [] "inside a")] (eval '(a)))
> "outside a"
>
> Is this really how these functions should behave?
Since let provides a lexical binding rather than a dynamic binding,
I'm not too surprised by the result.
Would the following do what you want?
(def ^{:dynamic true} *a* (fn [] "outside a"))
(binding [*a* (fn [] "inside a")] (load-string "(*a*)"))
(binding [*a* (fn [] "inside a")] (eval '(*a*)))
(FWIW, those yield "inside a" in both cases)
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/
"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en