Chapter 18State

There’s a fundamental irony to the Clojure approach to programming, which arises from a principle that can be summed up—at least in part—as avoid mutable state. Avoiding mutable state is why you can’t just jam a new value into the fifth element of an existing vector or delete a key from an existing map. It’s also why Clojure has let instead of local variables and why we restrain ourselves from defing things on the fly in production. The idea is the less mutable state we have—at least in production—the easier our programs are to understand.

Now for the irony: having gotten rid of all of the mutable state, we’re now at a loss when it comes to modeling things that do change over time. How, for example, do we keep track of our book-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.