the-ns

clojure.core

  • (the-ns x)
If passed a namespace, returns it. Else, when passed a symbol,
returns the namespace named by it, throwing an exception if not
found.

1 Example top

  • ;; 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)
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:3680 top

(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"))))))
Vars in clojure.core/the-ns:
Used in 0 other vars

Comments top

No comments for the-ns. Log in to add a comment.