If passed a namespace, returns it. Else, when passed a symbol,
returns the namespace named by it, throwing an exception if not
found.
;; Let's play with a namespace by its name and by its symbol user=> (def for-later-use (create-ns 'my-namespace)) #'user/for-later-use user=> (the-ns for-later-use) #<Namespace my-namespace> user=> (the-ns 'my-namespace) #<Namespace my-namespace> ;; not going to find anything this way because we just asked the repl ;; not to perform an evaluate on it and there is not such ;; namespace with the name "for-later-use" user=> (the-ns 'for-later-use) java.lang.Exception: No namespace: for-later-use found (NO_SOURCE_FILE:0) ;; not going to work either because "my-namespace" is the name of a namespace ;; and not a symbol that points to something user=> (the-ns my-namespace) java.lang.Exception: Unable to resolve symbol: my-namespace in this context (NO_SOURCE_FILE:12)
(defn the-ns
"If passed a namespace, returns it. Else, when passed a symbol,
returns the namespace named by it, throwing an exception if not
found."
{:added "1.0"
:static true}
^clojure.lang.Namespace [x]
(if (instance? clojure.lang.Namespace x)
x
(or (find-ns x) (throw (Exception. (str "No namespace: " x " found"))))))
Comments top
No comments for the-ns. Log in to add a comment.