I'm working through the Clojure examples in Stuart Halloway's "Programmming Clojure" and I've hit a snag when using binding:
(def foo 10)
; => '#user/foo
foo
; => 10
(binding [foo 42] foo)
; => 10
(binding [user/foo 42] foo)
; => 10
(binding [user/foo 42] (var-get #'user/foo))
; => 10
Why won't it give me 42?
This appears to be a bug in the 1.1.0-alpha-SNAPSHOT and it is reproducible on Linux, too.
If you go back now to the Clojure d/l page, that version seems to have been withdrawn and 1.0.0 is the "Featured" d/l.
And in 1.0.0 your example does bind 42.
On a related note:
its really easy to be bitten by bindings in this way when ever you run code in another thread. I have encountered problems like this when a function I call evaluates something through pmap instead of map when the code is actually executed on a thread from the thread-pool. agents will do this also i believe.
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