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
42, and you replace every occurrence of
42, then expression
get_answer(0) is referentially transparent.
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.