In my application I need to convert clojure keyword eg. :var_name into a string "var_name". Any ideas how that could be done?
user=> (doc name) ------------------------- clojure.core/name ([x]) Returns the name String of a string, symbol or keyword. nil user=> (name :var_name) "var_name"
Actually, it's just as easy to get the namespace portion of a keyword:
(name :foo/bar) => "bar" (namespace :foo/bar) => "foo"
Note that namespaces with multiple segments are separated with a '.', not a '/'
(namespace :foo/bar/baz) => throws exception: Invalid token: :foo/bar/baz (namespace :foo.bar/baz) => "foo.bar"
And this also works with namespace qualified keywords:
;; assuming in the namespace foo.bar (namespace ::baz) => "foo.bar" (name ::baz) => "baz"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With