in Programming retagged by
386 views
0 votes
0 votes
What is referential transparency?
in Programming retagged by
386 views

1 Answer

1 vote
1 vote

A context in a sentence is "referentially transparent" if replacing a term in that context by another term that refers to the same entity doesn't alter the meaning.

So in order to understand the meaning of the above line we have to understand what is meant by  context

Firstly, take a sentence like “Lucifer is bigger than a mouse” and erase the word “Lucifer” to leave a blank –

ie. “_____ is bigger than a mouse”. This line is called a context.

We can fill the blank in the context to get a meaningful sentence.

Now we can fill the blank with the words that have same meaning like

Blue whale or earth's largest animal

if you put any one of  the above two in the sentence then the meaning of the sentence will not change.

 Blue whale is bigger than a mouse

Earth's largest animal is bigger than a mouse

This is called referential integrity

  a CONTEXT is “referentially transparent” if we can fill the blank with different names for the same underlying thing without affecting the meaning of the sentence.


In programming, an expression is called referentially transparent if it can be replaced with its corresponding value without changing the program's behavior.

For eg:-

In C, for incrementing a value we can do x++ or ++x or x=x+1 i.e. they are doing the same thing but when we use them in a context i.e in a code like

y=x++;

or

y = ++x;

the meaning of the sentence will change i.e. they are not following referntial integrity.

but if we write

y= ++x;

or

y = x+1;

Both will give same result so these two codes follow referntial transparency.

 

 

1 comment

referential integrity is from databases 😊
0
0

Related questions