3

I'm trying to pretty print a list of namespaces:

(doseq [x (all-ns)] (println x))

This prints each namespace as #<Namespace xxxxx>. I would like to get each namespace as xxxxx (that is without the #<Namespace>. I tried to (name x), (symbol x) but I get ClassCastException clojure.lang.Namespace cannnot be cast to java.lang.Named, etc.

(doseq [x (all-ns)] (println (name x)))
(doseq [x (all-ns)] (println (str x)))
(doseq [x (all-ns)] (println (namespace x)))

How can I get the namespace as a string?

1
  • I realized that actually (doseq [x (all-ns)] (println (str x))) does work, I did have a typo when I tried. But ns-name as pointed in the answers is the function to use, better than str Commented Mar 14, 2016 at 20:36

2 Answers 2

7

Use ns-name:

(doseq [x (all-ns)] (println (ns-name x)))

Note that ns-name gives you a symbol. So if you want a string just use (str (ns-name ns)).

Sign up to request clarification or add additional context in comments.

Comments

2

Use the ns-name function:

(doseq [x (all-ns)] (println (ns-name x)))

Namespace function docs can be found here

Best of luck.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.