chapter sixteen
Before we introduce functions and macros in this section, it’s useful to refresh a few definitions about Clojure namespaces, vars and bindings.
Namespaces
- A "namespace" is an instance of
clojure.lang.Namespaceclass and is essentially a container for other objects.
- The "mapping table" is a dictionary object associated with each namespace. It contains mappings between Clojure symbols and objects such as vars or classes. Functions like intern or def adds items into the table, while ns-map shows the content.
- The "alias table" is another type of dictionary associated with a namespace. It contains relationships between namespaces, using a symbol as key and a namespace name as value. Items can be added to the alias table with
:asduring 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.Namespaceclass itself. Hence namespaces are "global", that is, the running process doesn’t need to hold an explicit reference to keep them alive (from the garbage collector perspective).