liveBook · Manning

Alias table

As explained in Clojure: The Essential Reference

An alias table is a namespace-associated mapping from aliases to the namespaces they designate.

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:

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

How Clojure: The Essential Reference covers it

How deep it goes
Defines the mapping and demonstrates adding, inspecting, and removing aliases without descending into namespace implementation internals.
Examples
Demonstrates alias, ns-aliases, ns-unalias, and :require with :as using named namespaces and vars.
What it assumes
Assumes familiarity with Clojure namespaces, vars, libraries, and qualified symbols.
What you can do after
Operate/configure namespace aliases with alias, ns-aliases, ns-unalias, and :as.
How it connects
Connects namespaces with vars, libraries, require, ns, and fully qualified symbol references.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.