There does not seem to be a canonical definition of "pure function", but the widespread language-agnostic understanding seems to be a function that
- has no side effects
- produces a value that is completely and uniquely determined by its explicit arguments
This appears to beg a question when the arguments are themselves mutable, especially if they are passed by the value of a reference. To take one example, suppose I pass an array x
to a function in C -- say it sums an array of int. For thinking about the purity of the function, how am I supposed to understand what has been passed? If I have a C understanding of it (forgive me for errors; I don't really speak C) then I have just passed a pointer, and whatever happens to be pointed to is a side-effect of the runtime behavior of the program. Yet for any given array of int, the function behaves in a fully predictable way, which seems pretty pure. So can a C function take an array as an argument and still be pure? (I want a language-agnostic answer, not a reference to the gcc docs.)