On Thu, Sep 17, 2009 at 2:49 PM, Stuart Sierra
<the.stuart.sie...@gmail.com>wrote:

>
> On Sep 17, 12:40 pm, Gorsal <s...@tewebs.com> wrote:
> > Oh. And just as a quick other question, do global bindings affect
> > threads which are started in the same ns?
>
> I think threads inherit the bindings in effect when they are created.


http://clojure.org/vars strongly implies otherwise; that they see the root
bindings except while a (binding [foo bar] (baz)) form is executing in the
same thread.

Having heritable bindings could be useful, though. Yet wouldn't work for
cases like pmap. Best might be to just use atoms when you want
non-thread-local dynamic bindings: (untested)

(def multiplier (atom 3))

(defn magnify [x]
  (* multiplier x))

(defmacro with-atom-value [[at v] & body]
  `(let [a# ~at
         x# (deref a#)]
     (reset! a# ~v)
     (try
       ~...@body
       (finally
         (reset! a# x#)))))

...

(with-atom-value [multiplier 4]
  (pmap magnify some-seq))

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to