O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required