D'oh! Thanks. I fall for that trap yet again. Sounds so simple when explained.
2010/2/9 Sean Devlin <francoisdev...@gmail.com>: > 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=> (binding [*v* 2] (doall (map f [1 1 1]))) > (3 3 3) > > Sean I know I've omitted this detail, but the actual code in question is actually *db* binding from clojure.contrib.sql, so I can't change it either way. doall works fine though. 2010/2/9 Richard Newman <holyg...@gmail.com>: > 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)))) > [1 1 1])) > > Obviously you wouldn't use it in this instance -- use doall, or better yet > rewrite your function to not use dynamic bindings -- but for larger jobs it > works fine. -- 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 Note that posts from new members are moderated - please be patient with your first post. 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