Skepdick wrote: ↑Sat Aug 07, 2021 7:42 am
The purpose of the discussion is whether the functions I am pointing out satisfy the definition.
You say "yes - they satisfy it".
I say "no - they don't".
You've convinced me that a function that does not return anything is a corner case of the definition of pure function. It's a small matter in any case.
Skepdick wrote: ↑Sat Aug 07, 2021 7:42 am
We seem to be interpreting the definition differently.
I agree with you that a function that doesn't return anything is a corner case of the definition.
Note that in general, a function in a programming language always returns a value. A function that doesn't return a value is sometimes called a procedure. In Python that distinction is not made. In C for example one explicitly declares a function that doesn't return a value as
The keyword void signals the caller not to expect a return value.
So the definition of a pure function is ambiguous in Python because of this corner case; but it's not ambiguous in all languages.
Skepdick wrote: ↑Sat Aug 07, 2021 7:42 am
That's precisely where we are diverging. The definition
only talks about functions which return a value. I am pointing out functions which
fail to return a value.
I already said in my earlier post that on reflection, I've come around to your point of view that a Python function that doesn't return a value is a corner case of the definition. The Wiki page on pure functions doesn't consider this case at all, so you have a point. But I already said earlier that I see your point, did you perhaps miss that?
Skepdick wrote: ↑Sat Aug 07, 2021 7:42 am
And it appears that you are insisting that the non-return of value (or the return of no value) is a value. That's a tautology.
I already said earlier that you convinced me. Why are you acting like you didn't read what I wrote?
For the record: The Wiki definition of pure function does not discuss the case of a function that doesn't return a value. Some programming languages, such as C, explicitly label these functions with a return value of "void" so that callers don't accidentally expect a return value.
In Python, there is no such distinction. Therefore in Python there is a corner case in the definition of pure function that doesn't cover a function that doesn't return a value.
This seems like a small point, I'm not sure why it concerns you so much. And I'm especially puzzled as to why you started the thread by talking about mathematical functions, since in math all functions are pure functions. All mathematical functions return outputs and the concept of side effect or external state is meaningless.
Skepdick wrote: ↑Sat Aug 07, 2021 3:31 pm
Great. So what's the domain of f(x) = x ?
To be mathematically precise, note that in math, a function is characterized by its domain and range as well as its inputs/outputs. So the function f(x) = x defined on the natural numbers is actually a different function than f(x) = x defined on the real numbers.
That's because set-theoretically, a function is a set of ordered pairs (x, f(x)). So the identity function on the reals includes the pair (pi, pi), whereas the identity function on the natural numbers does not include that pair.
Averroes wrote: ↑Sat Aug 07, 2021 3:00 pm
In the Python programming language, even when the keyword "return" is not used in the definition of a function, the function still returns a value! In that case, it returns the value "None". "None" is an object in Python! In Python everything is an object. The value "None" in Python is of the type NoneType. So, technically, every Python function defined in this thread, whether they explicitly used a return statement or not,were returning a value. Hence, they were functions and not procedures!
Good point! Thanks for the clarification.