Returns a map of the aliases for the namespace.
;; clojure.core contains an alias (ns-aliases 'clojure.core) ;;=> {jio #<Namespace clojure.java.io>} ;; To start with there are no namespace aliases in the user namespace. (ns-aliases 'user) ;;=> {} ;; ...but we can add an alias to the user namespace. (alias 'string 'clojure.string) (ns-aliases 'user) ;;=> {string #{Namespace clojure.string>}
;; Suppose you want to pass a namespace as an argument... (ns wip (:require [clojure.string :as string] [clojure.pprint :as pp])) (defn foo [nspace] nspace) ;; ...pretty easy to do if you use the namespace symbol. (foo (the-ns 'clojure.string)) ;;=> #<Namespace clojure.string> ;; but, a bit of a problem if you want to pass the alias. (foo (the-ns 'string)) ;; java.lang.Exception: No namespace: string found... ;; We can make a function that will serve using ns-aliases. (defn the-alias [name] (get (ns-aliases *ns*) name)) (the-alias 'string) ;;=> #<Namespace clojure.string> (foo (the-alias 'string)) ;;=> #<Namespace clojure.string> ;; A more direct function can be written. ;; but this uses an undocumented function. (defn the-alias [alias-name] (.lookupAlias *ns* (symbol alias-name))) (the-alias "pp") ;;=> #<Namespace clojure.pprint>
Add an alias in the current namespace to another namespace. Arguments are two symbols: the alias t...
ns-aliases