liveBook · Manning

Keyword

As explained in Clojure: The Essential Reference

A Clojure keyword is a named immutable value that can identify map keys and can itself perform associative lookup when invoked.

A Clojure keyword is a named immutable value commonly used as a map key. It is also callable: given associative data, it looks up the value stored under itself. section 15.1 section 8.2.2

Use a keyword directly as a function when its lookup role makes the code clearer. It accepts a map or another associative structure and can receive a fallback value when the key is absent. section 8.2.2

Lookup with a keyword

(:b {:a 1 :b 2}) ;; 2 (:c {:a 1 :b 2} "Not found") ;; "Not found"

Keywords fit several related operations:

  • Use them as map keys and invoke them for concise associative lookup. section 8.2.2
  • Use find when the result must preserve both the key and its value as a map entry. section 8.2.2

Qualified keywords

(def bx (keyword "b" "x")) [(namespace bx) (name bx)] ;; ["b" "x"] section 15.1

(symbol "s") ; #1
;; s

(keyword "k") ; #2
;; :k

Compare constructing a symbol and a keyword, including the keyword's printed form. section 15.1

How Clojure: The Essential Reference covers it

How deep it goes
Explains construction, qualification, invocation, defaults, and alternatives while deferring detailed reader validation rules.
Examples
Demonstrates keyword construction, qualified names, direct map lookup, fallback values, and comparison with get and find.
What it assumes
Assumes basic Clojure collection syntax and introduces keywords alongside symbols and associative lookup.
What you can do after
Apply it via direct invocation to retrieve map values, supply fallbacks, and choose explicit alternatives such as get or find.
How it connects
Connects keywords with maps, associative data structures, get, find, namespaces, and symbols.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.