2

According to docs dir lists only "public" vars. Indeed, it does not show itself, and may not be available in current namespace:

user=> (dir user)
nil
user=> 
user=> 
user=> (in-ns 'foo)
#<Namespace foo>
foo=> 
foo=> 
foo=> (dir foo)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: dir in this context, compiling:(NO_SOURCE_PATH:17)

What other (non-public) types of names/vars exist? (These are probably Java types?) How to list these non-public names? How are they imported into the namespace (or into some "default case" namespaces) on the startup? How default namespaces are searched through in runtime?

For instance in Python: dir() lists everything in current namespace, if a referenced variable is not found it is checked among dir(__builtins__).

xealits
  • 4,224
  • 4
  • 27
  • 36
  • Possible duplicate of [How to list the functions of a namespace?](https://stackoverflow.com/questions/2747294/how-to-list-the-functions-of-a-namespace) – Felipe Augusto Sep 27 '18 at 18:11

1 Answers1

8

This question was already answered here. You could list all public vars in a namespace using:

(keys (ns-publics 'foo))

There also is a dir function like python does, so you could do:

 (clojure.repl/dir foo)

EDIT

If you really want to see the privates as well, you could do:

(defn ns-all-vars[n]
   (filter (fn[[_ v]]
             (and (instance? clojure.lang.Var v)
                  (= n (.getName (.ns v)))))
      (ns-map n)))

and then simply call

(println (map first (ns-all-vars 'foo)))

To print all symbols in 'foo namespace.

Community
  • 1
  • 1
Shlomi
  • 4,708
  • 1
  • 23
  • 32