Is it? That's neat; I guess I've never thought about how the compiler treats def. Thanks for the explanation.
On Aug 15, 3:03 pm, Mark Rathwell <mark.rathw...@gmail.com> wrote: > deftest is a macro. Macros are expanded at compile time. So, in this > case, at compile time, a function called namespace2 is def'd with meta > data :test set to the body of your deftest. > > All of that body is namespace resolved in macro expansion, before > in-ns is ever executed (which happens when you actually call the > namespace2 function created by the macro). Put another way, (def > anything 10) is namespace resolved to (def > learn.clojure.test.core/anything 10) at macro expansion time (compile > time), before the test function is ever called, and thereby before > in-ns is ever executed. > > Hope this helps. > On Mon, Aug 15, 2011 at 5:07 PM, Richard Rattigan <ratti...@gmail.com> wrote: > > > I'm finding that namespaces don't seem to behave as I expect > > intuitively, or according to the reference. It's quite possible I'm in > > the wrong here though, as I'm just kicking clojure's tires at this > > point. > > > Here is the relevant doc: > > >http://clojure.org/special_forms > > (def symbol init?) > > Creates and interns or locates a global var with the name of symbol > > and a namespace of the value of the current namespace (*ns*). > > > In the test below, which succeeds, the var does not appear to end up > > in the "current namespace" per this definition. Am I misinterpreting > > something, or is this a deviation from the spec/reference? > > > (ns learn.clojure.test.core > > (:use [clojure.test])) > > (deftest namespace2 > > (in-ns 'my.new.namespace) > > ;confirm the current namespace > > (is (= "my.new.namespace" (str *ns*))) > > ;attempt to def a var in the current namespace > > (def anything 10) > > ;the var is not defined in the current namespace > > (is (nil? (ns-resolve *ns* 'anything))) > > ;the var is however definined in the orginal namespace > > (is (not (nil? (ns-resolve (find-ns 'learn.clojure.test.core) > > 'anything)))) > > (is (= 10 learn.clojure.test.core/anything))) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en