A property of programming languages, generally of functional languages, where an expression will always evaluate to the same value in any context. That is, the expression has a single value that cannot be changed by evaluating the expression or by allowing different parts of the program to share the expression, i.e. there are no side effects in the evaluation of expressions. Most quasi-functional languages and all imperative languages in general do not have this property, as they can operate by modifying state so the evaluation of a single expression may have different values at different times and in different contexts. Only pure functional languages can make the claim of being referentially transparent.

For a functional language to be considered referentially transparent, it must use static binding of variables. Using dynamic binding will result in an expression that contains a free variable to have different evaluations depending on the context where it is evaluated. Lazy evaluation or call by name semantics also are necessary to preserve this property, as use of call by value may result in expressions that might not terminate in some circumstances.

Referential transparency is considered a desirable property because it makes logical reasoning about the operation of a program possible, e.g., it may be possible to prove rigorously that a program is correct, and also facilitates the transformation of a program.

Log in or registerto write something here or to contact authors.