[Python-Dev] Re: Re: lists v. tuples
Andrew Koenig
ark@research.att.com
Tue, 15 Apr 2003 20:41:31 -0400 (EDT)
Guido> That's cute, but a bit too magical for my taste... It's not
Guido> immediately obvious how this would be done (I know how, but it
Guido> would require a lot of explaining). Plus, -1 is a perfectly
Guido> valid truth value.
Yes, I know that -1 is a valid truth value.
Here's the trick. The object of the game is to figure out whether
f is < or __cmp__.
Suppose you call f(x, y) and it returns 0. Then you don't care
which one f is, because x<y is false either way.
So the first time you care is the first time f(x, y) returns nonzero.
Now you can find out what kind of function f is by calling f(y, x).
If f(y, x) returns zero, f is <. Otherwise, it's a 3-way comparison.