On Sep 17, 11:30 am, Allen Rohner <[EMAIL PROTECTED]> wrote:
> > I don't see how this should work. The re-defined variable has thread-local
> > scope and shouldn't be viewable in other threads.
>
> Vars have thread-local scope. Defs are global.
>
Hmm...
def establishes the root binding of a var, said var being associated
with a name in a namespace. If the var already exists, def replaces
the root binding (but not the var). defn expands into def, so all this
applies to defn as well.
Root bindings are shared between threads, so a re-def will be seen by
already-running code in all threads.
binding establishes a per-thread binding for a var, hiding the root
binding and any prior bindings in this thread. A var that has a per-
thread binding can be set!, and those changes will be seen only in the
one thread. When the stack unwinds past the binding it is
disestablished, and the prior binding becomes visible again.
Idiomatic Clojure code that wants to treat a var as a true (thread-
local) variable should use binding and set!
While it is possible to make a globally visible change to a var with
def, the only appropriate scenarios for doing so are to fix a bug, or
for scratch vars at the repl.
Rich
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---