Clojure’s Solution

Clojure’s immutable data structures, managed reference types, and software transactional memory system combine to provide a model that’s both high level and much easier to use than locking concurrency. Let’s dig in with a look at an atom, which I find to be the simplest to understand of the reference types Clojure provides.

Atomic Power

As we saw in Chapter 8, Identity, Value, and State in Clojure, atoms are good for managing state that’s independent and to which we want to make synchronous changes. Here, independent means we can make the change without coordinating a change to any other piece of state. Synchronous means we want to block the thread that triggered the change until it’s done.

We can create an atom out of ...

Get Functional Programming: A PragPub Anthology 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.