Clojure Distilled: core concepts of the functional style
The guide argues that Clojure is hard to learn not because of its syntax, which it calls extremely simple, but because it requires learning new methods for solving problems: as a Lisp dialect it belongs to a different language family than mainstream languages, where most existing skills transfer easily. The author presents Clojure as a good fit for large applications because, as a functional language, it avoids global state and uses immutable data structures[1] by default. With mutable data, passing by value is safe but extremely inefficient, so most languages pass data by reference instead — fast, but it forces developers to know every place the data might be referenced, and the complexity grows with the size of the application. Immutable structures resolve this dilemma: every change creates a revision, giving the safety of copying at a cost proportional to the size of the change, and the language cleans up unused revisions the way garbage collection handles memory.
Data that is never modified in place makes it possible to write pure functions[2] — functions without side effects that return the same result for the same parameters regardless of global state — and such code is called referentially transparent[3]. Clojure keeps logic and data separate: all functions operate on a small set of common structures (lists, vectors, maps, and sets), so the function, representing one data transformation, becomes the core reusable component. Code expressed as a sequence of such transformations separates what is done from how it is done, which the guide calls declarative. Iteration is the example given: instead of writing a loop, one uses an iterator function and passes the logic to execute at each step as a parameter.
Pure functions can safely run in parallel, so mapping a function over a collection with map can simply be switched to pmap once operations prove time-consuming, making use of the extra cores. For shared state, Clojure provides a Software Transactional Memory (STM)[4] library that removes manual locking when working with threads; state backed by immutable data needs to be locked only for writing, since the current revision can be safely read while a new one is being generated.
Read the original yogthos.netDiscussion
Sources
-
yogthos.net
Clojure Distilled


