You're viewing version 1.2.0 of ns-publics. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16



  • (ns-publics ns)
Returns a map of the public intern mappings for the namespace.

2 Examples top

  • ;; create the namespace and switch to it
    user=> (in-ns 'demo.ns)
    #<Namespace demo.ns>
    ;; Make sure all of the good stuff in clojure.core is usable here, too.
    demo.ns=> (clojure.core/use 'clojure.core)
    ;; define some public functions
    demo.ns=> (defn public-fn1 [x y] (+ x y))
    demo.ns=> (defn public-fn2 [t] (* t t t))
    ;; define a private function with defn-
    demo.ns=> (defn- private-fn [s] (/ s 5))
    ;; Switch back to the user namespace
    demo.ns=> (in-ns 'user)
    #<Namespace user>
    ;; Get a map of all intern mappings for namespace demo.ns
    user=> (ns-interns 'demo.ns)
    {public-fn1 #'demo.ns/public-fn1, private-fn #'demo.ns/private-fn, public-fn2 #'demo.ns/public-fn2}
    ;; Now get a map of only the public mappings.  No private-fn here.
    user=> (ns-publics 'demo.ns)
    {public-fn1 #'demo.ns/public-fn1, public-fn2 #'demo.ns/public-fn2}
  • ;; See also for information on namespaces in Clojure and how to inspect and manipulate them
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:3232 top

(defn ns-publics
  "Returns a map of the public intern mappings for the namespace."
  {:added "1.0"}
  (let [ns (the-ns ns)]
    (filter-key val (fn [^clojure.lang.Var v] (and (instance? clojure.lang.Var v)
                                 (= ns (.ns v))
                                 (.isPublic v)))
                (ns-map ns))))
Vars in clojure.core/ns-publics: = and defn fn instance? let ns ns-map val
Used in 5 other vars apropos dir-fn apropos ns-vars ns-vars

Comments top

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