aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/with_ns.clj
diff options
context:
space:
mode:
authorStuart Sierra <mail@stuartsierra.com>2009-03-29 03:17:03 +0000
committerStuart Sierra <mail@stuartsierra.com>2009-03-29 03:17:03 +0000
commit2166ff44388e992b8671f7a49349a54f213b4dfb (patch)
treedad3bbe058b10abaf8de1e102c2b4f06641a706e /src/clojure/contrib/with_ns.clj
parent54827c622ba1567e5e5fb97e520bf6b2e1e69ce4 (diff)
with_ns.clj: added with-temp-ns, fixed handling of refer/use
Diffstat (limited to 'src/clojure/contrib/with_ns.clj')
-rw-r--r--src/clojure/contrib/with_ns.clj14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/clojure/contrib/with_ns.clj b/src/clojure/contrib/with_ns.clj
index 4b770cd5..202d3ae9 100644
--- a/src/clojure/contrib/with_ns.clj
+++ b/src/clojure/contrib/with_ns.clj
@@ -19,4 +19,16 @@
object or a symbol. This makes it possible to define functions in
namespaces other than the current one."
[ns & body]
- `(binding [*ns* (the-ns ~ns)] (eval '(do ~@body))))
+ `(binding [*ns* (the-ns ~ns)]
+ ~@(map (fn [form] `(eval '~form)) body)))
+
+(defmacro with-temp-ns
+ "Evaluates body in an anonymous namespace, which is then immediately
+ removed. The temporary namespace will 'refer' clojure.core."
+ [& body]
+ `(do (create-ns 'sym#)
+ (let [result# (with-ns 'sym#
+ (clojure.core/refer-clojure)
+ ~@body)]
+ (remove-ns 'sym#)
+ result#)))