Skip to Content
Clojure Programming
book

Clojure Programming

by Chas Emerick, Brian Carper, Christophe Grand
April 2012
Intermediate to advanced
628 pages
18h 42m
English
O'Reilly Media, Inc.
Content preview from Clojure Programming

Chapter 3. Collections and Data Structures

Maps, vectors, sets, and lists are the basic data structures provided by Clojure. As you’ve seen already, each of these has its own convenient literal notation:

'(a b :name 12.5)       ;; list

['a 'b :name 12.5]      ;; vector

{:name "Chas" :age 31}  ;; map

#{1 2 3}                ;; set

{Math/PI "~3.14"
 [:composite "key"] 42
 nil "nothing"}         ;; another map

#{{:first-name "chas" :last-name "emerick"}
  {:first-name "brian" :last-name "carper"}
  {:first-name "christophe" :last-name "grand"}}  ;; a set of maps

These categories of data structures and their notations are likely familiar to you for the most part; particularly with regard to notation, Ruby and Python are quite similar. However, Clojure data structures have a couple of distinctive characteristics:

  1. They are first and foremost used in terms of abstractions, not the details of concrete implementations.

  2. They are immutable and persistent, both essential to Clojure’s flavor of efficient functional programming.

Each data structure has its own characteristics and idiomatic patterns of usage that we’ll explore progressively, but it is far more important to internalize the above points and what they imply about Clojure, its data structures, and how you can and should design your Clojure applications.

Abstractions over Implementations

It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures.[72]

—Alan J. Perlis in the foreword to Structure and Interpretation of Computer Programs

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning Clojure

Learning Clojure

Adam Bard
Practical Clojure

Practical Clojure

Luke VanderHart, Stuart Sierra
Getting Clojure

Getting Clojure

Russ Olsen

Publisher Resources

ISBN: 9781449310387Errata Page