1

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 ?

murtaza52
  • 46,887
  • 28
  • 84
  • 120
  • 1
    Yes [Var](https://github.com/clojure/clojure/blob/653b8465845a78ef7543e0a250078eea2d56b659/src/jvm/clojure/lang/Var.java) is implemented as a java class and is used for thread bindings, metadata, validation etc. – Lee Aug 02 '19 at 16:41

1 Answers1

2

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.

Alan Thompson
  • 29,276
  • 6
  • 41
  • 48