Talk:Referential transparency

Latest comment: 3 months ago by Wnbeser in topic Formal Definitions section unclear

Potential New Source

edit

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)Reply

Garbled Sentence?

edit

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)Reply

Program behavior

edit

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 (++g)*0.

Nxvar 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)Reply

  • @Jochen Burghardt: I think Søndergaard, Harald; Sestoft, Peter (1990). "Referential transparency, definiteness and unfoldability" (PDF). Acta Informatica. 27 (6): 505–517. doi:10.1007/bf00277387. 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)Reply

@Ruud Koot: 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)Reply

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

I just noticed that Nxvar 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)Reply

Incorrect definition

edit

@Jochen Burghardt: @Nbarth: @Bertrand Meyer:

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)Reply

Confusion in first example

edit

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 GetInput(Source) where Source might identify a particular disk file, the keyboard, etc. Even with identical values of Source, 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)Reply

Formal Definitions section unclear

edit

The whole section is very unclear and assumes the reader is already knowledgable about the topic.

* It first mentions the concepts of referential transparency, definiteness, and unfoldability, but it's difficult to see where each topic is addressed in the following text.
* Where are the definitions anyways? Most of the section is just examples ranging from abstract constructions of expression trees in some lispy syntax to natural language.
* Overall, the whole section is all over the place lacking structure and necessary context (or links to such context) around the topics introduced for the unacquainted reader to be able to understand it. Wnbeser (talk) 13:40, 18 September 2024 (UTC)Reply
  NODES
Idea 1
idea 1
INTERN 1
Note 2
Project 10