A namespace mapping table is the dictionary associated with a Clojure namespace. It maps symbols to objects, especially vars and classes, and provides the main mechanism for resolving names during evaluation. section 16.0 section 16.8
The mapping table changes as namespaces are created and configured:
- Creating a namespace adds default imports; ns also adds public clojure.core vars, making standard functions directly available. section 16.6
- ns-map returns the table, whose entries commonly have symbol keys and var or class values. section 16.8
- ns-unmap removes a symbol from one namespace without deleting the underlying function or var from the system; refer can restore access. section 16.8
Inspecting and using a mapping
A mapping can be treated as a map lookup: (def user-ns-mapping (ns-map 'user)) obtains the table, and ('+ user-ns-mapping) retrieves the var for +. Calling that result with 1 and 1 produces 2. section 16.0
(def user-ns-mapping (ns-map 'user)) ; #1
(def lookup-var ('+ user-ns-mapping)) ; #2
(lookup-var 1 1) ; #3
;; 2
Browse the compact example showing namespace inspection, symbol lookup, var retrieval, and invocation. section 16.0
