Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the name of a function whose result depends only on its parameters?

I'm writing a toy compiler thingy which can optimise function calls if the result depends only on the values of the arguments. So functions like xor and concatenate depend only on their inputs, calling them with the same input always gives the same output. But functions like time and rand depend on "hidden" program state, and calling them with the same input may give different output. I'm just trying to figure out what the adjective is that distinguishes these two types of function, like "isomorphic" or "re-entrant" or something. Can someone tell me the word I'm looking for?

like image 461
Matthew Exon Avatar asked Dec 02 '22 06:12

Matthew Exon


2 Answers

The term you are looking for is Pure

  • http://en.wikipedia.org/wiki/Pure_function
like image 139
JaredPar Avatar answered Dec 04 '22 21:12

JaredPar


I think it's called Pure Function:

In computer programming, a function may be described as pure if both these statements about the function hold:

  • The function always evaluates the same result value given the same argument value(s). The function result value cannot depend on any hidden information or state that may change as program execution proceeds or between different executions of the program, nor can it depend on any external input from I/O devices.
  • Evaluation of the result does not cause any semantically observable side effect or output, such as mutation of mutable objects or output to I/O devices.

The result value need not depend on all (or any) of the argument values. However, it must depend on nothing other than the argument values.

like image 37
Anton Gogolev Avatar answered Dec 04 '22 21:12

Anton Gogolev