Talk:Referential transparency

Potential New Source
I would like to cite this keynote presentation from Rich Hickey (or a transcript thereof) and use ideas from it to improve the quality of this article, and to more efficiently communicate the meaning of the term referential transparency as it pertains to computer science. Any objections to this? Tyler (talk) 14:25, 13 April 2016 (UTC)

Garbled Sentence?
I don't understand "Without referential transparency, such difference can be easily made and utilized in programs." Is there an example? — Preceding unsigned comment added by 199.16.140.25 (talk) 01:03, 26 May 2016 (UTC)

Program behavior
I had tagged the lead sentence This means that a particular expression instance can be replaced with its corresponding value without changing the program's behavior. with the following clarification request: An expression can evaluate to the same value in every context, but have a side effect. In this case, replacing it by its value does change the program behavior. A C example is . removed my request and added "John C. Mitchel (2002). Concepts in Programming Languages. Cambridge University Press. p. 78" as a source. I don't have access to this book and hence can't check whether Mitchel requires the expression to be side-effect free, or excludes e.g. changes of global variables from his notion of "program behavior". If none of both restrictions apply, I still insist on my statement made in the clarify request. I suggest the lead should be rephrased accrodingly. - Jochen Burghardt (talk) 19:06, 2 September 2016 (UTC)


 * I think had an answer to this question in it. I only quickly skimmed it again, but the definition currently in the article is the "Strachey" definition, which indeed only holds in a side-effect free setting. —Ruud 20:42, 2 September 2016 (UTC)

This article is really hard (philosophical) stuff! What about just mentioning the restriction to a side-effect free setting in the lead, for now? - Jochen Burghardt (talk) 07:40, 3 September 2016 (UTC)


 * Sure, that would at least make the article a bit more correct. —Ruud 11:19, 3 September 2016 (UTC)

I just noticed that also had changed the definition of a referential transparent expression from "all its defined instances produce the same values" to "can be replaced with its corresponding value without changing the program's behavior", thereby resolving my clarification request. Sorry for the confusion! (It might still be helpful to state somewhere in the article that the former is a necessary condition for the latter, and in a side-effect free setting also a sufficient condition, when a good source is available for that.) - Jochen Burghardt (talk) 09:51, 4 September 2016 (UTC)

Incorrect definition
The current definition of referential transparency in the article is incorrect:

"An expression is called referentially transparent if it can be replaced with its corresponding value without changing the program's behavior."

Referential transparency is not a property of an expression but of a language, that is of a given syntax and semantics (languages with the same syntax but different semantics are different languages, so one can be referentially transparent while the other referentially opaque). And it is not about being able to replace an expression with its value, but with an equivalent expression, that is an expression with the same value/denotation/referent/meaning.

From the comments of the Stack Overflow answer in the references:

https://stackoverflow.com/a/11740176/2326961

"A language is referentially transparent if two program fragments that represent the same denotation (and hence "equivalent") can be exchanged for each other without affecting anything else. It is not the program fragments that are referentially transparent. Referential transparency is a property of the whole language which allows us to replace equivalent fragments by each other."

- Uday Reddy

https://stackoverflow.com/a/9859966/2326961

"Fantastic! A welcome relief to popular misconceptions about RT, e.g., tying it to functions. Or defining via replacing an expression with its value (as on Wikipedia)--oddly so since expressions and values are different kinds of things. Perhaps one place where people go wrong in considering RT-ness of imperative languages is to assume that these "values" are simple things like numbers rather than more complex things like functions from a store."

- Conal

Maggyero (talk) 22:42, 17 April 2020 (UTC)

Confusion in first example
Here's some of the wording for the first example:

"Consider a function that returns the input from some source. In pseudocode, a call to this function might be  where   might identify a particular disk file, the keyboard, etc. Even with identical values of , the successive return values will be different."

I don't quite follow. If you read the same exact file from disk twice in a row, how will the second time be different? Seems like that second sentence is wrong, no? Or maybe I'm missing something? Arigoldx (talk) 02:23, 13 January 2022 (UTC)