How to convert a keyword to a string?

In clojure, what is the idiomatic way of converting a keyword:

:some-keyword

in line:

"some-keyword"
+3
source share
2 answers

use the name for this:

user=> (name :some-keyword)
"some-keyword"
+10
source

As Alex Ott noted, name is the best function for this, clojure.contrib also has a function that you can call for any type: as-str , which does this too:

(str :foo :bar)     ;;=> ":foo:bar"
(as-str :foo :bar)  ;;=> "foobar" 

See http://clojure.github.com/clojure-contrib/string-api.html#clojure.contrib.string/as-str

+2
source

All Articles