Is 0 > None??

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Fri Aug 31 11:50:00 EDT 2001


Fri, 31 Aug 2001 16:36:23 +0200, Alex Martelli <aleax at aleax.it> pisze:

> Comparing a blue camel to a rocking horse is fine -- comparing it
> to a complex number isn't.

Complex numbers aren't the only exception. Comparing a blue camel to
a rocking horse is not fine if they are instances of classes which
define __cmp__ to something unfriendly.

Perhaps an interesting idea would be to separate two concepts of
comparison:

  * <, >, <=, >= work on homogeneous objects and provide some natural
    order appropriate for their meaning. it doesn't have to have the
    property I don't know English name for: that
        forall x y. (x <= y) or (y <= x)
    e.g. among sets an appropriate definition would be being a subset.
    x<y should be the same as x<=y and x!=y, not necessarily the same as
    not (x>=y).

  * cmp gives a total order among everything, not necessarily very
    meaningful but with the above property. It's similar to Python's
    cmp from the time it worked on complex numbers.

== and != belong to both families at the same time. There is no
conceptual problem with finding the answer for very different objects
(they are just unequal). The amount compared is supposed to be the
same for both kinds of comparisons.

If it's a good design, we should find a way to introduce it smoothly
without breaking too much.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list