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:
“What sought they thus afar?
Bright jewels of the mine?
The wealthy of seas, the spoils of war?
They sought a faiths pure shrine!
Ay, call it holy ground,
The soil where first they trod;
They have left unstained what there they found,
Freedom to worship God.”
—Felicia Dorothea Hemans (17831835)
“For me being a poet is a job rather than an activity. I feel I have a function in society, neither more nor less meaningful than any other simple job. I feel it is part of my work to make poetry more accessible to people who have had their rights withdrawn from them.”
—Jeni Couzyn (b. 1942)