A question on modification of a list via a function invocation

Steve D'Aprano steve+python at pearwood.info
Fri Sep 8 11:15:18 EDT 2017


On Fri, 8 Sep 2017 01:01 pm, Rustom Mody wrote:

> On Friday, September 8, 2017 at 7:39:38 AM UTC+5:30, Steve D'Aprano wrote:


>> Rustom, I've already given you the definitive answer to your question about
>> how to define `is` without talking about memory. You haven't replied or
>> acknowledged it, so here is it again:
>> 
>> `is` compares the two operands for identity.
> 
> Preamble… so far so good
> 
>> If the two operands are the same
>> object, `is` returns True, if they are distinct objects, `is` returns False.
> 
> restated
> a is b iff a is b

I hope you are not seriously claiming this is a circular argument.

The first half of your restatement, before the "iff", represents *Python code*,
not natural language, and needs to be quoted[1] to make sense.

If you don't quote it, you are just stating a tautology: a is b iff a is b,
which is true by definition, no matter what meaning we assign to the word "is".

But that's not what I'm saying, and you are wrong to accuse me of giving a
tautology. I'm referring to the Python expression (which is source code in a
programming language which merely looks a bit like English), and explaining it
in English terms.

The "is" in the first half is not the same as the "is" in the second, which
makes the sentence non-circular. This would be more obvious if we were having
this discussion in (say) Hindi, Latin, Swahili, or German:

    `A is B` ob und nur wenn A ist B

(Or should that be "ob und nur ob"? Google Translate prefers the first, but I
have my doubts.)

If Python used a mathematical symbol instead of the word "is" as the operator,
it also would obviously be non-circular:

    `A ≡ B` if and only if A is B

The mere happenstance that:

(1) Python uses the English word "is" as the operator, rather than some other
symbol like `≡` or `===` or `≣` or `.ist.`; and

(2) we happen to be writing in English, rather than (say) Japanese or Russian or
Esperanto or the Black Speech of Mordor;

does not make my argument circular. You have been lead astray by the mere
contingent fact that Python uses `is` for the operator, instead of some other
symbol.

Don't be fooled: the operator `is` is not the same as the English word "is".

But you know that, so I'm not sure why you are trying to misrepresent my
argument as circular.

So let us start repairing your restatement by adding quotation marks. I use ``
rather than "" because that's the convention used in Markdown for displaying
inline code, and I'm quoting the code:

    `a is b` if and only if a is b

is not circular, but it's not very clear[2]. I intentionally avoided using the
English word "is" (not to be confused with the Python operator `is`) in my
explanation, because I knew it would confuse people and lead them astray. So
let us use a better explanation, one which is less likely to give a misleading
impression:

    `a is b` if and only if the two operands are the same object

which is closer to what I actually said and avoids giving the mistaken
impression of circular reasoning.

Now if you want to argue about the definition of "same", I have already stated
my position: the commonsense or intuitive meaning of "the same thing" is
sufficient here. If you disagree, then it is up to you to demonstrate a problem
with the commonsense meaning in this context.


>> This does require that we agree on "same object", which as you point out is
>> (in its full generality) a difficult thing to define.
> 
> More than difficult, impossible in the fully abstract philosophical case

Fortunately, the fully abstract philosophical case is irrelevant here.


[...]
> E.g. in the past I've raised
>> the paradox of My Grandfather's Axe.
> 
> Dont see the relevance (here)

The paradox of the axe is one illustration of the difficulty in defining "the
same" in full generality. When objects persist through time and are subject to
change, there are questions raised about what it means to say that something is
the same when all its component bits have been replaced.

So I'm agreeing with you[2] that "the same" in its full generality is difficult
to define in a non-paradoxical way.


>> But the intuitive, common-sense notion of "same object" is, I think,
>> sufficient here. If you want to argue that it is *not* sufficient, I think
>> it's up to you to demonstrate a problem with the definition.
>> 
> 
> Its not that you cant raise philosophical problems if you want
> But when concretized to (basic) math, there are no disputes
> so the argument becomes obtuseness to no point

I'm afraid I have no idea what you think you are saying here.


> In the case of python data model every single interminable thread like this
> one, obviously started by a noob asking something genuinely and indicating
> a real confusion disproves your claim to obvious intuition and common sense

The Original Poster wasn't confused by "sameness". The OP was confusing by
scoping and mutation.

You have to go back to 15 August to find the beginning of the thread, but the OP
was having problems reconciling his expectations of how he thought Python
behaved with how it actually behaved. If I understood his initial questions
correctly, he expected that given:


def test(alist):
    alist=[3, 6, 9]

def test1(alist):
    alist[0] = 3

blist = [1, 2, 3]
test(blist)
test1(blist)


one of two things would happen:

(1) Either alist inside the function test() would alias the global variable
blist (like call by reference), and *both* test() and test1() would change the
value of blist;

(2) Or alist would be a copy of blist (like call by value), and *neither* test()
nor test1() would change the value of blist.


He was confused that *only* test1() changed the value of blist, not about the
question of `is` or "same object". 


> Just to reiterate: Someone asked a question
> Its not clear what (s)he understood from what we have going on and on about
> for 100s of posts

I believe that the OP got their answer long before you started raising
philosophical questions about the nature of "is" and "identity". The OP's last
comment was on the 17th August; your first comment was nearly 12 hours later,
and it was eighteen days later that you claimed:

"Its the “== is id” mess that is at the base of the mess"

I don't know how you reached that conclusion. It seems irrelevant to the OP's
problem.



>> Can you show an actual false positive (two distinct objects for which `is`
>> returns True) or false negative (the same object given as both operands for
>> `is` nevertheless returns False)? In the absence of any actual bugs in the
>> definition, I maintain that it is sufficient.
> 
> You are not paying attention — the example above I gave in which
> python arbitrarily hi-handedly, inconsistently manifests different behavior
> between integer 1 and tuple (1,2)

I don't see the relevance. As you have been told an uncountably infinite number
of times now[3], Python is under no obligation to meet your intuitions about
which immutable objects it caches.


> I am now dropping off this thread [more important things to do]
> with this observation:

I don't know whether to be relieved or disappointed.





[1] The convention in English at least, is to distinguish between uses of a
phrase and mentions of a phrase by quoting or italics. Here quoting is more
convenient. An example of the USE-MENTION distinction is this quine:

    "Is a sentence fragment" is a sentence fragment.

Without the quotation marks, it isn't even grammatical, let alone correct.



[2] Try not to faint, and I'll try not to let it happen again *wink*

[3] Not that I would ever exaggerate.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list