Permalink
Browse files

Successful call to 'ns registers it in *loaded-libs* This enables REP…

…L successful use cases such as =>(ns a) nil =>(ns b (:require a)) nil

Signed-off-by: Rich Hickey <richhickey@gmail.com>
  • Loading branch information...
1 parent f48d024 commit f11e70726553685bda222ccd37c28addcfc519c7 @laurentpetit laurentpetit committed with richhickey Nov 29, 2012
Showing with 18 additions and 1 deletion.
  1. +4 −1 src/clj/clojure/core.clj
  2. +14 −0 test/clojure/test_clojure/repl.clj
View
@@ -5223,7 +5223,10 @@
~@(when gen-class-call (list gen-class-call))
~@(when (and (not= name 'clojure.core) (not-any? #(= :refer-clojure (first %)) references))
`((clojure.core/refer '~'clojure.core)))
- ~@(map process-reference references)))))
+ ~@(map process-reference references))
+ (if (.equals '~name 'clojure.core)
+ nil
+ (do (dosync (commute @#'*loaded-libs* conj '~name)) nil)))))
(defmacro refer-clojure
"Same as (refer 'clojure.core <filters>)"
@@ -35,3 +35,17 @@
(is (some #{'defmacro} (apropos 'defmacro)))
(is (some #{'defmacro} (apropos 'efmac)))
(is (= [] (apropos 'nothing-has-this-name)))))
+
+
+(defmacro call-ns
+ "Call ns with a unique namespace name. Return the result of calling ns"
+ [] `(ns a#))
+(defmacro call-ns-sym
+ "Call ns wih a unique namespace name. Return the namespace symbol."
+ [] `(do (ns a#) 'a#))
+
+(deftest test-dynamic-ns
+ (testing "a call to ns returns nil"
+ (is (= nil (call-ns))))
+ (testing "requiring a dynamically created ns should not throw an exception"
+ (is (= nil (let [a (call-ns-sym)] (require a))))))

1 comment on commit f11e707

Member

dmiller commented on f11e707 Dec 27, 2012

I'm not sure if it matters, but test-dynamic-ns will have the side-effect of changing ns.

Please sign in to comment.