ns-publics

clojure.core

  • (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)
    nil
    
    ;; define some public functions
    demo.ns=> (defn public-fn1 [x y] (+ x y))
    #'demo.ns/public-fn1
    demo.ns=> (defn public-fn2 [t] (* t t t))
    #'demo.ns/public-fn2
    
    ;; define a private function with defn-
    demo.ns=> (defn- private-fn [s] (/ s 5))
    #'demo.ns/private-fn
    
    ;; 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 http://clojure.org/namespaces 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:3716 top

(defn ns-publics
  "Returns a map of the public intern mappings for the namespace."
  {:added "1.0"
   :static true}
  [ns]
  (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:
Used in 0 other vars

Comments top

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