Reputation: 47441
Why does clojure have symbols mapped to vars, instead they being mapped directly to values ? What is the idea behind the 2 way indirection of symbol resolving to a var, and a var referencing a value ?
What is var actually, is it just a memory reference, or a java class which does much more ?
The docs says that this is needed so that the values can be redefined, however why cant they redefined if there was no 2 way indirection ?
Upvotes: 1
Views: 99
Reputation: 29984
You can find a detailed description of the Clojure var
mechanism here: When to use a Var instead of a function?
Since Clojure data is immutable, you need an indirection mechanism like a var
or atom
to allow for "change". This is a bit like having a variable name
in Java, which is actually a pointer to a string like Fred
. Later, you may reassign name
to point to a different string Barney
.
Upvotes: 2