In Clojure, there are a handful of global variables that you can set!
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
OK, thanks. The apparent "globalness" is not the piece I want to imitate. I want to make a var available for users to set!, where the var controls overall behavior of how the library operates.
I understand that I can just declare the var dynamic, and then they can control it with the binding construct, but I want users to be able to set! it once and forget about it.
--
I believe one can mimic the functionality with alter-var-root! (I haven't tried it though), but I'd rather imitate core's style of using set! for those sorts of overall controlling variables.
To expand on what Marko said, the set!able Vars that come with Clojure just have thread-local bindings created already in the REPL thread. They're really only meant to aid developers working at the REPL, rather than to be set! as part of normal running code.
As far as I understand it, set! modifies the thread-local binding, just like the binding macro, but doesn't delimit a definite scope of validity for the binding. You can set! any dynamic var with the same semantics.
alter-var-root works fine for that purpose, e.g.
https://github.com/michaelklishin/monger/blob/master/src/clojure/monger/core.clj#L168-171
--
Still, it would be nice to understand whether it's possible to achieve the same effect as Clojure core's settable vars.