diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clojure/contrib/with_ns.clj | 14 |
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#))) |