tags:

views:

108

answers:

1

In my application I need to convert clojure keyword eg. :var_name into a string "var_name". Any ideas how that could be done?

+14  A: 
user=> (doc name)
-------------------------
clojure.core/name
([x])
  Returns the name String of a string, symbol or keyword.
nil
user=> (name :var_name)
"var_name"
kotarak
I cannot imagine a more complete answer, but just for fun I shall dare someone to come up with it.
Hamish Grubijan
@Hamish Perhaps by adding `(source name)`?
ponzao
How `name` works should not be of interest. The docstring is the contract. Anything else is an implementation detail, one should not rely upon.
kotarak
Thanks! My initial reaction was to do this: (.replaceFirst (.toString (keyword "abc")) ":" "")
Bart J
Thanks kotarak! I am loving this Clojure more every day! This is my third day.
Santosh
@BartJ: `(doc subs)` => `(subs (str (keyword "abc")) 1)` ;)
kotarak
@user448587: You are welcome. :)
kotarak
@kotarak: I guess that shows my Java inclination ;)
Bart J