Before introducing the functions and macros in this section, it’s useful to refresh a few definitions about Clojure namespaces, vars and local bindings.
Namespaces
- A "namespace" is an instance of
clojure.lang.Namespace
class and is essentially a container for other objects. It contains a mapping table and an alias table.
- The "mapping table" is a dictionary associated with each namespace. It contains a mapping between Clojure symbols and objects such as vars or classes. Functions like intern or def adds items into the table, while ns-map shows its content.
- The "alias table" is another type of dictionary associated with a namespace. It contains relationships with other namespaces, using a symbol as key and a namespace name as value. Items can be added to the alias table with
:as
during namespace creation or with the alias function. ns-aliases shows its content.
- Once a namespace is created, a reference is added to the "global namespace repository". This is a static map inside the
clojure.lang.Namespace
class itself. It derives that namespaces are "global", that is, the running process doesn’t need to hold an explicit namespace reference to keep them alive (from the garbage collector perspective).