Yesterday I was doing Clojure Koans with a friend who really wanted to
learn Clojure. When he first understood the mutable nature of Vars, he
was really turned off by it. I could actually see his disappointment.
He asked me what the rationale for this was, and I was not able to
tell him.
So, long story short, why are namespaces in Clojure mutable? What is
the rationale behind this?
The next time someone asks me, I would like to be prepared :)
Cheers,
Alf
It's for REPL development. Everytime you redefine a function, its Var
needs to be updated.
OTOH, redefining a var during the normal course of operation is frowned upon.
For this reason, defs should always be top level (modulo an enclosing
let, or something).
The only official way to change a Var value during normal operation is
binding, which is thread local and dynamically scoped (bound Vars can
also be set! while bound, still thread locally), so its semantics are
well defined, if a bit more obscure than normal lexical/immutable let.
kind regards
Thanks Herwig, makes sense.
Cheers,
Alf
--
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