Skip to content

Commit f11e707

Browse files
laurentpetitrichhickey
authored andcommitted
Successful call to 'ns registers it in *loaded-libs* This enables REPL successful use cases such as =>(ns a) nil =>(ns b (:require a)) nil
Signed-off-by: Rich Hickey <richhickey@gmail.com>
1 parent f48d024 commit f11e707

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/clj/clojure/core.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5223,7 +5223,10 @@
52235223
~@(when gen-class-call (list gen-class-call))
52245224
~@(when (and (not= name 'clojure.core) (not-any? #(= :refer-clojure (first %)) references))
52255225
`((clojure.core/refer '~'clojure.core)))
5226-
~@(map process-reference references)))))
5226+
~@(map process-reference references))
5227+
(if (.equals '~name 'clojure.core)
5228+
nil
5229+
(do (dosync (commute @#'*loaded-libs* conj '~name)) nil)))))
52275230

52285231
(defmacro refer-clojure
52295232
"Same as (refer 'clojure.core <filters>)"

test/clojure/test_clojure/repl.clj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,17 @@
3535
(is (some #{'defmacro} (apropos 'defmacro)))
3636
(is (some #{'defmacro} (apropos 'efmac)))
3737
(is (= [] (apropos 'nothing-has-this-name)))))
38+
39+
40+
(defmacro call-ns
41+
"Call ns with a unique namespace name. Return the result of calling ns"
42+
[] `(ns a#))
43+
(defmacro call-ns-sym
44+
"Call ns wih a unique namespace name. Return the namespace symbol."
45+
[] `(do (ns a#) 'a#))
46+
47+
(deftest test-dynamic-ns
48+
(testing "a call to ns returns nil"
49+
(is (= nil (call-ns))))
50+
(testing "requiring a dynamically created ns should not throw an exception"
51+
(is (= nil (let [a (call-ns-sym)] (require a))))))

0 commit comments

Comments
 (0)