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".
We seem to be interpreting the definition differently.
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.
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.
This is not an equivalent analogy. I am not arguing different fruits: apples vs oranges. I am arguing fruits vs non-fruits. I address this further below.
And I am pointing out a distinction between two functions which is a sufficient difference to re-classify a function as impure.
I disagree.
False analogy.
Values and non-values are both... ???. So if we are counting total pieces of ??? there's no relevant difference between values and non-values, even though there is a difference between them.
But, of course that's a contradiction. You are basically saying that a difference is not a difference. There IS a difference. You are choosing to discard information using some yet-unstated relevance metric.
I'm not actually arguing about anything either. I am using the "perfectly clear" Wiki definition too. I don't prefer a different definition - I am using the same definition you prefer.
If we are both using the same definition. And we are both talking about the same functions - how come we are arriving at different classification schemes? How come you are classifying some functions as pure and I am classifying them as impure?
Why do we disagree? Why are our respective sorting functions producing different outputs for the same inputs?
You are using the english determiner "the". What do you think is THE authoritative specification and THE authoritative documentation for pure functions?
My observations are conflicted with your words. You SAY that you are not one of those people, but I am observing you being one of those people so I don't know whether to trust my eyes or your words.wtf wrote: ↑Fri Aug 06, 2021 3:49 am If a function does not return a value but the caller assigns the return to a value, that's a coding error and would indeed result in undefined behavior.
I don't think we have any substantive disagreement. Your disagreement seems to be with Wikipedia or the computer scientists who define pure functions a particular way. I'm not any of those people.
As I have already demonstrated "x=5" can be re-written as a function without a return value!
Code: Select all
def assign_x(y):
global x
x = y
And since you can pass absolutely ANY valid object from the Mathematical Universe can be passed as a parameter to the assign_x() function I am simply asking you the question: Is None/nil/null a valid, assignable object?
OK, great! I agree with you 100%
So can you point me to a pure function which implements Mathematical equality?
Code: Select all
def equal(x,y):
# Implement logic to return a Boolean(True of False)
# such that assertions below pass.
assert equal(0,0)
assert equal(1,1)
assert not equal(0,1)
No, my point is that there is ONLY one pure function. NOOP. def f(): pass
Everything else is an impure function. The definition attempts to distinguish between inputs and input-streams, but that's just special pleading.
Inputs are the same things as streams of unit-length 1.
Outputs are the same thing as streams of unit-length 1.
It does matter to cryptographers. Side-channel attacks (timing attacks) are a real thing. NO-OPS are used for padding the runtime of a function so that the algorithm can be made to appear as executing with O(1) time-complexity.wtf wrote: ↑Fri Aug 06, 2021 3:49 am I'm not very computer science-y, I can't muster much emotion over this point. No actual programmer would write a function that does nothing and returns nothing. Well ok, every machine instruction set includes a NO-OP instruction for timing purposes. Is a NO-OP a pure function? I don't know, does it really matter? It's just a corner case of a definition.
That is precisely what makes these two functions different. Runtime.
Code: Select all
def f(): pass
def g(): x**x
OK, but can you live with "any function that takes inputs; or produces outputs" is impure?
If you can't live with it.... can you put forth an example of a pure implementation of equality for the domain of integers?
Yes. Cryptographers. But this is beyond the point.
OK, so using the above definition: What is the domain of the assignment function? What can you assign to x?
Computationally, the answer is "ANYTHING that exists in the domain can be assigned to x".
Invoking the value of x is the same thing as invoking a function which returns x as value.
Call-by-value vs call-by-reference.
Code: Select all
In [1]: x = None
In [2]: def y(): pass
In [3]: type(x)
Out[3]: NoneType
In [4]: type(y())
Out[4]: NoneType
no limits/constraints on you whatsoever.
So the really important question then is this: Is there anything that you can not assign to x?