ClojureDocs

Nav

Namespaces

keyword?

clojure.core

Available since 1.0 (source)
  • (keyword? x)
Return true if x is a Keyword
1 Example
(keyword? 'x)
;;=> false

(keyword? :x)
;;=> true

(keyword? true)
;;=> false

;; Note: some of the keywords below are non-conformant and will not work
;; with destructuring. For more info see 'keyword'.

(keyword? :-)
;;=> true

(keyword? :+)
;;=> true

(keyword? :-o)
;;=> true

(keyword? :')
;;=> true

(keyword? :#)
;;=> true

(keyword? :</>)
;;=> true

(keyword? :'/-)
;;=> true

(keyword? :'//-)
;;=> true

(keyword? :////)
;;=> true

(keyword? :'//-,)
;;=> true

(keyword? :'//,-)
;;=> ArityException Wrong number of args (2) passed to: core/keyword?  clojure.lang.AFn.throwArity (AFn.java:429)
;; Note: the comma is taken as space, so the code above is equivalent to
(keyword? :'// -)

(keyword? :-:)
;;=> RuntimeException Invalid token: :-:  clojure.lang.Util.runtimeException (Util.java:221)
;;=> RuntimeException Unmatched delimiter: )  clojure.lang.Util.runtimeException (Util.java:221)
;; https://clojure.org/reference/reader states:
;; "Symbols beginning or ending with ':' are reserved by Clojure."

(keyword? :-:-)
;;=> true
;; https://clojure.org/reference/reader states:
;; "A symbol can contain one or more non-repeating ':'s" and:
;; "Keywords are like symbols, [...]"

(keyword? :....)
;;=> true

(keyword? :,,,,)
;;=> RuntimeException Invalid token: :  clojure.lang.Util.runtimeException (Util.java:221)
;;=> RuntimeException Unmatched delimiter: )  clojure.lang.Util.runtimeException (Util.java:221)
;; Note: the comma is taken as space, so the code above is equivalent to
(keyword? :    )

(keyword? :a:b:c)
;;=> true

(keyword? :a.b.c)
;;=> true

(keyword? :73)
;;=> true

See Also

Return true if x is a keyword without a namespace

Added by svenschoenung

Return true if x is a keyword with a namespace

Added by svenschoenung

Returns a Keyword with the given namespace and name. Do not use : in the keyword strings, it will...

Added by cljlc
0 Notes
No notes for keyword?