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. 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:
“The whole fauna of human fantasies, their marine vegetation, drifts and luxuriates in the dimly lit zones of human activity, as though plaiting thick tresses of darkness. Here, too, appear the lighthouses of the mind, with their outward resemblance to less pure symbols. The gateway to mystery swings open at the touch of human weakness and we have entered the realms of darkness. One false step, one slurred syllable together reveal a mans thoughts.”
—Louis Aragon (18971982)
“Uses are always much broader than functions, and usually far less contentious. The word function carries overtones of purpose and propriety, of concern with why something was developed rather than with how it has actually been found useful. The function of automobiles is to transport people and objects, but they are used for a variety of other purposesas homes, offices, bedrooms, henhouses, jetties, breakwaters, even offensive weapons.”
—Frank Smith (b. 1928)