Semantics of ==

Axel Boldt axelboldt at yahoo.com
Fri Mar 26 08:45:53 EST 2004


Erik Max Francis <max at alcyone.com> wrote

> What part of the semantics are you unclear about?  Two sequences are
> equal if they are element-wise equal.

That definition is circular.

> That is the definition that people rely on, 

Yes.

> that's the definition that the interpreter uses,

No.

> and that definition is even consistent with the behavior you saw with the
> self-referencing lists which for some reason surprised you.

Yes, s==w is consistent with the definition, but s!=w would also have
been consistent with it.

Consider for instance the following definition: 
* all strings and numbers are called "well-founded"
* a list is called well-founded if and only if all its elements are
well-founded.

l=[]
l.append(l)
Is l well-founded? Both answers "yes" and "no" are consistent with the
above definition. If you write a program to determine whether a given
list is well-founded, it will run into an infinite loop. Similarly, if
you try to write a program implementing the above simple-minded
definition of list-equality, it'll run into an infinite loop. Since
Python does not run into an infinite loop, it must use a different
definition.

Axel



More information about the Python-list mailing list