Namespaces, Symbols, and Keywords

Like symbols and vars, namespaces are just ordinary Clojure values, accessible to the mortal Clojure programmer. You can, for example, get at the current namespace: it’s always bound to the symbol *ns*, so that

 (println ​"Current ns:"​ *ns*)

will print something like

 Current ns​:​ #object[clojure.lang.Namespace 0x76c706bf user]

You can also look up any existing namespace by name:

 (find-ns ​'user​) ​; Get the namespace called 'user.

With a namespace in hand, you can discover all the things defined in that namespace, so that this:

 (ns-map (find-ns ​'user​)) ​; Includes all the predefined vars.

will give you a very large map of symbols to vars, essentially everything the user namespace knows about:

 {primitives-classnames ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.