Purity

Iain Buclaw ibuclaw at ubuntu.com
Fri Dec 17 00:36:03 PST 2010


== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> http://www.reddit.com/r/programming/comments/enajl/purity_in_d_language/
> Bye,
> bearophile

The way I see it, there are 4 ways of describing the purity of a function. Though the comments on them are slightly vague and
different to the way I'll describe it, the way I assume them to be treated in D <-> GCC is:

Pure if the function has no effects except the return value, which depends only on parameters, and may read (but not write to)
global memory.
Constly Pure if the function does not read global memory (immutable data being the only notable exception because of the way it's
treated) and has no effects except the return value.
Weakly Pure if the function does not read global memory, but may have arbitrary side effects, such as a method altering it's local
state.
Impure if the function may write into global memory/have other side effects that won't appropriately categorize it into the above.

Regards
Iain


More information about the Digitalmars-d mailing list