Semantics of ==
Erik Max Francis
max at alcyone.com
Thu Mar 18 18:25:08 EST 2004
Axel Boldt wrote:
> ...and then it can run into an infinite loop. I explained that for the
> example s==w in the part you deleted. The recursion does not always
> have a base case; the rule does not always give a definite truth
> value.
But the == operator doesn't run into an infinite loop, so this is much
ado about nothing.
> ... i.e. such a fun case. If there really is an implementation
> dependency hidden in something as fundamental as == for lists, that'd
> better be mentioned in the language reference.
I don't know what you're talking about here. The behavior you saw with
your s == w example is completely consistent with Python's definition of
equality and Python's definition of equal sequences. You have some
additional equivalence in your mind that simply does not apply to
Python.
> > How can you define the value of an arbitrary object without
> > reference to
> > its internal structure?
>
> Well, you claim that s and w have the same value yet different
> internal structure, so you must work with some definition of "value"
> that's different from internal structure. I don't know what it is, and
> the language reference doesn't fully specify it.
1 and 1.0 have different internal structure, but they're equal. This is
an obvious existence proof that Python simply does not follow the
equivalence that you're thinking of.
Equality does _not_ indicate equivalence in internal structure in
Python. This is especially true in Python where users can define their
own equality behavior, so you can make it whatever you want -- you can
make your own instance that compares equal (or unequal) with absolutely
everything. If 1 == 1.0 didn't convince you, surely this will convince
you that equality and equivalence in internal structure are not related
in Python.
> I.e., I'm interesting in a function val : lists -> strings with the
> property val(l1) == val(l2) iff l1 == l2. That would also considerably
> clarify the semantics of == for lists, which I still don't understand.
Why are you interested in such a function?
--
__ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ I do not promise to consider race or religion in my appointments.
I promise only that I will not consider them. -- John F. Kennedy
More information about the Python-list
mailing list