Tuesday, March 27, 2012

3.5



a.) The factorial function is referentially transparent because it is a function that is only produces one and only one output based on the input.  Unless you do not know what the input will be or there are multiple different inputs;, therefore making the factorial function non referentially transparent.

b.) A function which waits for a key to be pressed then returns pressed key is not referentially transparent because you do know what will be pressed, so using just a value would not be logical.

c.) A function that counts the number of times it is called cannot be a referentially transparent function because it needs to run in order to see what the value is it will output.  

No comments:

Post a Comment