Pure Function

Pure Function

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

  1. 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.
  2. 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. The function may return multiple result values and these conditions must apply to all returned values for the function to be considered pure. If an argument is call by reference it is considered to be a combination of one argument and one return value and so the argument will get overwritten; because of this call by reference will make an expression impure even if the function called is pure.

Read more about Pure Function:  Pure Expressions, Impure Functions in Pure Expressions, See Also

Famous quotes containing the words pure and/or function:

    “What I want is a strange conjunction with you—” he said quietly; “Mnot meeting and mingling;Myou are quite right:Mbut an equilibrium, a pure balance of two single beings:Mas the stars balance each other.”
    —D.H. (David Herbert)

    The press and politicians. A delicate relationship. Too close, and danger ensues. Too far apart and democracy itself cannot function without the essential exchange of information. Creative leaks, a discreet lunch, interchange in the Lobby, the art of the unattributable telephone call, late at night.
    Howard Brenton (b. 1942)