liveBook · Manning

Referential transparency

As explained in Clojure: The Essential Reference

Referential transparency is the property that an expression can be replaced by its value without changing program behavior, because the value depends only on the expression's inputs.

Referential transparency means a function’s return value depends only on its parameters and nothing else. An expression can therefore be replaced by that value without changing program behavior. This property supports predictable composition and is associated with laziness, immutable values, and infinite sequences. section 2.1.2

Parameter-only behavior

A function that multiplies its argument by the current time or a random number is not referentially transparent: repeated evaluation can produce different results even with the same apparent input. Clojure’s function syntax can express both concise lambdas and explicit fn forms. section 2.1.2

How Clojure: The Essential Reference covers it

How deep it goes
Defines parameter dependence and names consequences, but stops short of a formal substitution procedure.
Examples
Contrasts random and time-dependent multiplication with anonymous fn syntax and ordinary parameterized functions.
What it assumes
Assumes basic functions and parameters while introducing the functional-language context from those foundations.
What you can do after
Evaluate whether a function’s result depends exclusively on its parameters.
How it connects
Connects referential transparency with higher-order functions, laziness, immutable values, and infinite sequences.

Also explained in

Compare how 9 books explain referential transparency →

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.