Semantics of ==

Axel Boldt axelboldt at yahoo.com
Thu Mar 25 08:32:58 EST 2004


Erik Max Francis <max at alcyone.com> wrote
> 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.

Well, it's precisely the point: the definition of list equality given
in the language reference is circular, but the implementation of ==
clearly is not, so the two don't coincide. I'm trying to understand
what the precise semantics of == for lists is. Right now, if you give
me two list definitions, I don't feel confident to determine whether
they are equal or not, without starting 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?

Like I said, it would clarify the semantics of == for lists. Another
use would be to hash on values of lists. (The FAQ 4.18 recommends to
first convert a list to a tuple and hash on that, but of course that
doesn't work in general. The ListWrapper class in 4.18 also works only
for simple minded lists.)

Axel



More information about the Python-list mailing list