An alias table is a dictionary associated with a Clojure namespace. It maps symbols to other namespaces, giving long namespace names shorter, readable references. section 16.0 section 16.7
Control alias mappings through a small interface:
- alias adds a symbol-to-namespace relationship. section 16.0 section 16.7
- ns-aliases displays the mappings for a namespace. section 16.0 section 16.7
- ns-unalias removes an alias entry. section 16.7
- The :as option in ns :require creates an alias when the namespace can load from a file. section 16.7
Shortening a namespace reference
After creating a namespace, assign it the alias myns: (alias 'myns 'com.web.tired-of-typing-this.myns). The alias table then contains myns mapped to the original namespace, so myns/myvar resolves to the var holding 0.
(def user-ns-mapping (ns-map 'user)) ; #1
(def lookup-var ('+ user-ns-mapping)) ; #2
(lookup-var 1 1) ; #3
;; 2
A related namespace mapping table resolves symbols such as + to vars; alias tables instead resolve alias symbols to namespaces. section 16.0
