Referential transparency

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

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:


Ask me anything / Suggestions

If you have any suggestions or questions (related to this or any other topic), feel free to contact me.

ℹī¸ More info


If you find this site useful in any way, please consider donating. I'm trying to keep it as clean and fast as possible - there are no ads, no affiliate links, and no analytics/tracking scripts.