This Goes with That

Virtually all modern programming languages include some kind of data structure that lets you associate arbitrary keys with equally arbitrary values, and Clojure is no exception. Appropriately enough, Clojure calls its arbitrary mapping data structure a map. In keeping with Clojure’s barebones philosophy, the map literal syntax only requires a pair of curly braces and some key/value pairs. For instance, this:

 {​"title"​ ​"Oliver Twist"​ ​"author"​ ​"Dickens"​ ​"published"​ 1838}

creates a map that associates the string "title" with "Oliver Twist", "author" with "Dickens", and "published" with 1838.

You can also cook up a new map with the hash-map function:

 (hash-map ​"title"​ ​"Oliver Twist"
 "author" ...

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.