Referential transparency

📄 BetterWays.dev wiki page | 🕑 Last updated: Feb 5, 2022

undefined

In a practical sense, the expression is referentially transparent if you can replace every occurrence of the expression with its value, and the result will be the same.

i.e. if the expression get_answer(0) returns 42, and you replace every occurrence of get_answer(0) with 42, then expression get_answer(0) is referentially transparent.

Note that get_answer ALWAYS must return the same output for the same input.

While theoretically, the referentially transparent function can be impure (i.e. it can create some irrelevant side effect in the process), the pure function must always be referentially transparent.

See also:


Comments and suggestions

You can use this form to submit a suggestion or a comment.

If you find this site useful, please consider supporting it. Supporters also get access to some extras.