1.3.0 permalink Arrow_down_16x16



  • (in-ns name)
Sets *ns* to the namespace named by the symbol, creating it if needed.

2 Examples top

  • ;; Let's create new namespace, create new variable in it, then access it from another namespace
    ;; create the namespace and switch to it
    user=> (in-ns 'first-namespace)
    #<Namespace first-namespace>
    ;; create a variable and check it
    first-namespace=> (def my-var "some value")
    first-namespace=> my-var
    "some value"
    ;; create another namespace and switch to this one
    first-namespace=> (in-ns 'second-namespace)
    #<Namespace second-namespace>
    ;; use variable from the other namespace here
    second-namespace=> first-namespace/my-var
    "some value"
  • ;; The "in-ns" function works almost the same as "ns", but does not load clojure.core 
    user=> (in-ns 'my-namespace)
    #<Namespace my-namespace>
    ;; the function clojure.core/inc won't just work
    my-namespace=> (inc 1)
    java.lang.Exception: Unable to resolve symbol: inc in this context (NO_SOURCE_FILE:15)
    my-namespace=> (clojure.core/inc 1)
Log in to add / edit an example.

See Also top

  • 0

    Sets *ns* to the namespace named by name (unevaluated), creating it

Log in to add a see also.

Comments top

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