operator overloading

François Pinard pinard at iro.umontreal.ca
Tue Jun 6 11:06:57 EDT 2000


david_ullrich at my-deja.com writes:

> This reminds me of a question that I've never got around to asking: Are
> there implicit requirements on __cmp__, like the order it defines has
> to be transitive, __cmp(a,b)__ has to be the opposite of __cmp(b,a)__, etc?

If one wants tools like `sort()' to work properly, `__cmp__' should establish
a proper order relation, yes.  Otherwise, rather cryptic bugs might pop out.

However, to give a special meaning to `<=', say, one might surely play
tricks and not use `__cmp__' as it was meant to be.  A butterfly is surely
free to travel nearby a fire :-).

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list