3

In clojure, what is the idiomatic way to convert a keyword:

:some-keyword

to a string:

"some-keyword"
Svante
  • 50,694
  • 11
  • 78
  • 122
yazz.com
  • 57,320
  • 66
  • 234
  • 385

2 Answers2

10

use name to do this:

user=> (name :some-keyword)
"some-keyword"
Alex Ott
  • 80,552
  • 8
  • 87
  • 132
2

As Alex Ott mentionned, name is the best function for this, clojure.contrib also has a function you can call on 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

Alex Miller
  • 69,183
  • 25
  • 122
  • 167
pyr
  • 424
  • 4
  • 2