Pure function
Encyclopedia : P : PU : PUR : Pure function
A function is pure if it always returns the same output on the same input. This is a component of referential transparency.
Examples of pure functions
Arithmetic functions are pure, and they are the archetype.Examples of impure functions
today() is impure, as at different times it will yield different results: it refers to some global state.Similarly, any function that uses global state or a static variable is potentially impure.
random() is impure, as each call potentially yields a different value.
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
