D'oh! Thanks.
I fall for that trap yet again. Sounds so simple when explained.
2010/2/9 Sean Devlin :
> The problem is that map returns a lazy seq, and the lazy seq is
> evaluated outside of the binding by the REPL. If you add a doall
> inside the binding, it behaves as you expect.
>
> user=> (b
You can also capture the binding. This looks a little ugly, but it
works: it grabs the binding eagerly, and returns a closure that
dynamically binds it when the function is invoked.
(binding [*v* 2]
(map (let [v *v*]
(fn [n]
(binding [*v* v]
(f n
gt; I have a question about the scope of "binding" of a var.
>
> Let's say I have the following var:
>
> (def *v* 1)
>
> And I define a function that uses it:
>
> (defn f [n] (+ *v* n))
>
> "binding" behaves as expected, establishing a thread-l
Hi,
I have a question about the scope of "binding" of a var.
Let's say I have the following var:
(def *v* 1)
And I define a function that uses it:
(defn f [n] (+ *v* n))
"binding" behaves as expected, establishing a thread-local binding to
a new valu