aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/ns_utils.clj
diff options
context:
space:
mode:
authorAaron Bedra and Stuart Halloway <pair@thinkrelevance.com>2009-08-23 13:09:53 -0400
committerAaron Bedra and Stuart Halloway <pair@thinkrelevance.com>2009-08-23 13:09:53 -0400
commitcf4790b017ab4d2840f9d224abfa9c6023f71262 (patch)
tree83858019c5136c5d50959f99808942701fb89dbd /src/clojure/contrib/ns_utils.clj
parent6b763062af9568c1b069d5f86c8d5481a3fdfeea (diff)
added test-expect source, renamed namespaces for contrib
Diffstat (limited to 'src/clojure/contrib/ns_utils.clj')
-rw-r--r--src/clojure/contrib/ns_utils.clj17
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..0d9075a9 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, value,
+ 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 (.isBound var)
+ (intern *ns* sym (var-get var))
+ (intern *ns* sym))))))