liveBook · Manning

Persistent data structure

As explained in Clojure: The Essential Reference

A persistent data structure is an immutable collection that preserves prior versions when updated, typically through structural sharing.

A persistent data structure is an immutable collection: an update produces a new value while preserving the prior version. This behavior gives Clojure a practical foundation for sharing data safely, including concurrent programs that avoid explicit locking by default. section 14.0 section 9.1.1

Persistent collections make several guarantees visible in everyday Clojure code:

  • Operations return collection values rather than requiring in-place mutation; earlier values remain available. section 9.1.1 section 16.13
  • Different collection types retain their own contracts: array-map preserves insertion order during iteration, while remaining associative like hash-map. section 11.1.2
  • Persistent values can be shared across concurrent computations without making every ordinary update an explicit locking operation. section 14.0

An update preserves the original map

(def original (array-map :a 1 :b 2)) (def updated (assoc original :c 3)) original ; => {:a 1, :b 2} updated ; => {:a 1, :b 2, :c 3} (array-map :a 1 :b 2) ; insertion order is retained during iteration section 11.1.2

How Clojure: The Essential Reference covers it

How deep it goes
Defines immutability and demonstrates concrete collection contracts, but stops short of explaining implementation internals such as structural sharing.
Examples
Uses seq views, array-map construction and promotion, metadata cloning, and concurrent-state examples.
What it assumes
Assumes familiarity with Clojure collections and assoc-like updates while teaching immutable collection behavior through concrete examples.
What you can do after
Apply it via Clojure collections to retain earlier values while producing updated maps, sequences, sets, or vectors.
How it connects
Connects immutability with concurrency, sequences, maps, metadata, and reference types.

Also explained in

Compare how 3 books explain persistent data structure →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.