On Jan 24, 6:40 am, CuppoJava <patrickli_2...@hotmail.com> wrote: > Thanks for the reply. That seems to match well with how I thought they > were supposed to work. > > I'm just a little confused by the > set!, with-local-vars, functions. What are they supposed to be used > for? > > -Patrick
Vars are mutable reference types just like atoms and refs, but whereas atoms and refs are intended to hold data shared across threads, The most common "mutable" use for vars is *thread-local* binding, using the binding macro. Of course, most of the time, they're just effectively immutable containers for global (def'd) values. To put it another way, the root binding of a var is supposed to remain constant, but dynamic binding allows you to affect its value within a single thread of execution. That's also why set! only works if the var is thread-locally bound; Threads must not be affected by uncoordinated change in another thread. (For that, there's the atom type) alter-var-root is sometimes useful (though dangerous), but I still haven't found a good use for with-local-vars -- Jarkko -- 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