diff options
Diffstat (limited to 'src/clojure/contrib/ns_utils.clj')
-rw-r--r-- | src/clojure/contrib/ns_utils.clj | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/clojure/contrib/ns_utils.clj b/src/clojure/contrib/ns_utils.clj index 7a866d5a..d77b3217 100644 --- a/src/clojure/contrib/ns_utils.clj +++ b/src/clojure/contrib/ns_utils.clj @@ -22,6 +22,9 @@ ;; 'print-docs' prints documentation for the public vars in a ;; namespace ;; +;; 'immigrate' Create a public var in this namespace for each +;; public var in the namespaces named by ns-names. +;; From James Reeves ;; Convenience ;; ;; 'vars' returns a sorted seq of symbols naming public vars @@ -87,3 +90,17 @@ "Prints documentation for the public vars in a namespace" [nsname] `(print-docs (get-ns '~nsname))) + +(defn immigrate + "Create a public var in this namespace for each public var in the + namespaces named by ns-names. The created vars have the same name, root + binding, and metadata as the original except that their :ns metadata + value is this namespace." + [& ns-names] + (doseq [ns ns-names] + (require ns) + (doseq [[sym var] (ns-publics ns)] + (let [sym (with-meta sym (assoc (meta var) :ns *ns*))] + (if (.hasRoot var) + (intern *ns* sym (.getRoot var)) + (intern *ns* sym)))))) |