O'Reilly logo

Clojure Programming by Brian Carper, Christophe Grand, Chas Emerick

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

On the Importance of Values

The notion of program state is a broad one with a long history, but in general, it refers to all of the scalars and aggregate data structures that you use to represent entities within your application, along with all of the connections that your application maintains with the external world (such as open files, sockets, and so on). Much of the character of a programming language is determined by its posture toward handling state: what it provides, what it prevents, and what it encourages.

Most programming languages, either through idiom or explicit design, encourage the use of mutable state, whether within the guise of objects or not. Functional programming languages tend to encourage the use of immutable objects—referred to as values—to represent program state. Clojure is no different in this respect.

“But wait,” you might say, “talking about eliminating mutability doesn’t make any sense—my programs need to do things in the world, so changing state is inevitable.” You would certainly be right in that all useful programs need to interact with the outside world, to take input and deliver output…

image with no caption

Figure 2-1. A diagram of all programs ever[37]

…but this does not preclude the use of immutable values. On the contrary, the more you can make your program rely upon operations over values, the easier it will be to reason about the program’s behavior compared with what ...

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