We can change things in many ways in Clojure, however most of the time it looks like we change things, we are merely making new things from the old ones. For example, when we add two numbers we dont actually change either number, instead we create a third number that is the result.

In this section you will learn about how to change things, first by using existing parts of Clojure, then by writing your own behaviour. When we define our own behaviour we can wrapping it up in function and give that function a name.

The functions from Clojure and the ones we create ourselves will be used with the collections from the previous section.

We will also introduce the following functions for the first time:

  • assoc, update, update-in - return collections with new or changed values

Putting things together with assoc

Using the assoc function we can add values to an existing collection

FIXME: more detail

Updating data with update & update-in

Using the update function, we can update values in an existing collection. Update uses a function to update the value, this could be something as simple as inc or a more complex function.

FIXME: more detail