Keywords

While a map will let you use virtually anything for a key, Clojure programmers commonly use keywords as keys. Like strings, numbers, and Booleans, keywords are a basic data type that comes packaged with Clojure. Syntactically, a keyword literal starts with a colon and then follows the same rules as symbols. Thus any of the following are fine keywords:

 :title
 :author
 :published
 :word-count
 :preface&introduction
 :chapter-1-and-2

You can look at keywords as a sort of subspecies of a string: both are just a sequence of characters. The reason we have both keywords and strings is that, like vectors and lists, they are good at different things. Strings are data. If you read an author’s name or title from a file, you’ll probably store ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.