Whether a program behaves differently if expressions and their values are interchanged
This article is about referential transparency in programming language theory. For its use in linguistics and philosophy, see Opaque context.
In analytic philosophy and computer science, referential transparency and referential opacity are properties of linguistic constructions,[1] and by extension of languages. A linguistic construction is called referentially transparent when for any expression built from it, replacing a subexpression with another one that denotes the same value[2] does not change the value of the expression.[3][4] Otherwise, it is called referentially opaque. Each expression built from a referentially opaque linguistic construction states something about a subexpression, whereas each expression built from a referentially transparent linguistic construction states something not about a subexpression, meaning that the subexpressions are ‘transparent’ to the expression, acting merely as ‘references’ to something else.[5] For example, the linguistic construction ‘_ was wise’ is referentially transparent (e.g., Socrates was wise is equivalent to The founder of Western philosophy was wise) but ‘_ said _’ is referentially opaque (e.g., Xenophon said ‘Socrates was wise’ is not equivalent to Xenophon said ‘The founder of Western philosophy was wise’).
Referential transparency depends on the values associated to expressions, that is on the semantics of the language. So, both declarative languages and imperative languages can be referentially transparent or referentially opaque, according to the semantics they are given.
The importance of referential transparency is that it allows the programmer and the compiler to reason about program behavior as a rewrite system. This can help in proving correctness, simplifying an algorithm, assisting in modifying code without breaking it, or optimizing code by means of memoization, common subexpression elimination, lazy evaluation, or parallelization.
^A linguistic construction (also called mode of containment, context, or operator) is an expression with holes.
^Here a value is the denotation (also called meaning, object, or referent) of an expression, not the result of the evaluation process.
^Quine, Willard Van Orman (1960). Word and Object (1st ed.). Cambridge, Massachusetts: MIT Press. p. 144. ISBN 978-0-262-17001-7.
^Strachey, Christopher (1967). Fundamental Concepts in Programming Languages (Technical report). Lecture notes for the International Summer School in Computer Programming at Copenhagen. Also: Strachey, Christopher (2000). "Fundamental Concepts in Programming Languages". Higher-Order and Symbolic Computation. 13 (1–2): 11–49. doi:10.1023/A:1010000313106. S2CID 14124601.
^Whitehead, Alfred North; Russell, Bertrand (1927). Principia Mathematica. Vol. 1 (2nd ed.). Cambridge: Cambridge University Press. p. 665. ISBN 978-0-521-06791-1.
and 19 Related for: Referential transparency information
In analytic philosophy and computer science, referentialtransparency and referential opacity are properties of linguistic constructions, and by extension...
transparency, independence of location Order-independent transparency in 3D computer graphics Referentialtransparency Security through transparency,...
constant with respect to that argument list (sometimes called referentialtransparency or idempotence), i.e., calling the pure function again with the...
functional programming (in which it is connected to the property of referentialtransparency). The term was introduced by American mathematician Benjamin Peirce...
variables, mutable reference arguments or input streams, i.e., referentialtransparency), and the function has no side effects (no mutation of local static...
sentence, has referentialtransparency: it is either referentially transparent or referentially opaque. A construction is referentially transparent if...
improve the efficiency of functional languages while maintaining referentialtransparency. Unique types can also be used to integrate functional and imperative...
return value. This style handles state changes without losing the referentialtransparency of the program expressions. Purely functional programming consists...
Circle–ellipse problem Composition over inheritance Program refinement Referentialtransparency Type signature SOLID – the "L" in "SOLID" stands for Liskov substitution...
mutable state Functionality doctrine, in intellectual property law Referentialtransparency This disambiguation page lists articles associated with the title...
Inscrutability of reference Masked-man fallacy Pure functions Referentialtransparency Transitivity of identity "Definition of "opaque context" | Collins...
identifiers and prevents accidental capture. This property is called referentialtransparency. In cases where capture is desired, some systems allow the programmer...
"L-value", "ad hoc polymorphism", "parametric polymorphism", and "referentialtransparency". The lecture notes were reprinted in 2000 in a special issue of...
Processing model Opaque context — another problem for compositionality Referentialtransparency — in programming languages Semantic decomposition (natural language...
dialect of Lisp provides a macro-writing system which provides the referentialtransparency that eliminates both types of capture problem. This type of macro...