Vars, Bindings, and Namespaces
When you define an object with def or defn, that object is stored in a Clojure var. For example, the following def creates a var named user/foo:
(def foo 10) | |
-> #'user/foo |
The symbol user/foo refers to a var that is bound to the value 10. If you ask Clojure to evaluate the symbol foo, it will return the value of the associated var:
foo | |
-> 10 |
The initial value of a var is called its root binding. Sometimes it is useful to have thread-local bindings for a var; this is covered in Managing Per-Thread State with Vars.
You can refer to a var directly. The var special form returns a var itself, not the var’s value:
(var a-symbol) |
You can use var to return the var bound to user/foo:
(var foo) | |
-> ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access