Oh yes you guys are right. I should have look at the source first:
(defmacro dir
"Prints a sorted directory of public vars in a namespace"
[nsname]
`(doseq [v# (dir-fn '~nsname)]
(println v#)))
from it, we can see the "quote" thing. Thank you all. I got it now!
On Oct 27, 5:12 pm, Ben Smith-Mannschott <[email protected]>
wrote:
> dir is a macro. It doesn't evaluate its arguments. So when you say
> (dir *ns*), Clojure sees: show me what's in the namespace named
> "*ns*", and there is no such namespace because *ns* is the name of a
> variable which contains the name of the current namespace.
>
> Dir is this way because for interactive use, it's convenient not to
> have to quote the symbol naming the namespace. So (dir user) and (dir
> clojure.core) should work.
>
> In your situation you'll want to call dir-fn, which is a function that
> will evaluate its arguments, so:
>
> if we assume (= *ns* 'user) (i.e. you're currently in the namespace "user")
> (dir-fn *ns*)
> is equivalent to
> (dir-fn 'user)
> and
> (dir user)
>
> HTH
> // Ben
>
>
>
>
>
>
>
> On Thu, Oct 27, 2011 at 10:57, jaime <[email protected]> wrote:
> > Hi there, when I tried to execute "(dir *ns*)" in REPL, I found it
> > doesn't work -- with exception of:
> > Exception No namespace: *ns* found clojure.core/the-ns
> > (core.clj:3689)
> > I'm not sure if I used it the right way. Following are my execution
> > tries:
> > =============================================================
> > Clojure 1.3.0
> > user=> (doc dir)
> > -------------------------
> > clojure.repl/dir
> > ([nsname])
> > Macro
> > Prints a sorted directory of public vars in a namespace
> > nil
> > user=> (dir *ns*)
> > Exception No namespace: *ns* found clojure.core/the-ns (core.clj:
> > 3689)
> > user=> *ns*
> > #<Namespace user>
> > user=> (the-ns *ns*)
> > #<Namespace user>
> > user=> (the-ns 'user)
> > #<Namespace user>
> > user=>
> > =============================================================
> > Any suggestions??
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to [email protected]
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en