(name x)
Returns the name String of a string, symbol or keyword.
;; the name of the keyword is without the ':'
;; "str" will retain the ':'.
(name :x)
;;=> "x"
(name "x")
;;=> "x"
;; returns the symbol name as a string without the namespace.
(name 'x)
;;=> "x"
(name 'user/x)
;;=> "x"
;; throws an error for invalid types, no nil punning
(name nil)
;;=> Error: Doesn't support name:
(name 2)
;;=> Error: Doesn't support name: 2
;; Note that for namespaced keywords, (name) only returns the keyword part.
(name :my-ns/my-key)
;;=> "my-key"
;; If you want the namespace part, you can use (namespace):
(namespace :my-ns/my-key)
;;=> "my-ns"
;; Using (str) will give you both parts, but also includes the leading colon.
(str :my-ns/my-key)
;;=> ":my-ns/my-key"
;; To get full key
(defn keyname [key] (str (namespace key) "/" (name key)))
(keyname :ns/key)
=> "ns/key"
(keyname :ns/deep/key)
=> "ns/deep/key"
;; Just for fun
(string/replace :key/val #"^:" "")
=> "key/val"