Skip to content

Commit

Permalink
Successful call to 'ns registers it in *loaded-libs* This enables REP…
Browse files Browse the repository at this point in the history
…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
laurentpetit authored and richhickey committed Dec 11, 2012
1 parent f48d024 commit f11e707
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/clj/clojure/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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>)"
Expand Down
14 changes: 14 additions & 0 deletions test/clojure/test_clojure/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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

@dmiller
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.