Re: [Python-3000] Please re-add __cmp__ to python 3000

2007-10-17 Thread Greg Ewing
Steven Bethard wrote: > I'm having troubles coming up with things where the *basic* operator > is really a cmp-like function. Think of things like comparing a tuple. You need to work your way along and recursively compare the elements. The decision about when to stop always involves ==, whatever c

Re: [Python-3000] Please re-add __cmp__ to python 3000

2007-10-17 Thread Greg Ewing
David A. Wheeler wrote: > But mixins for comparison are a BIG LOSER for sort performance Why not provide a __richcmp__ method that directly connects with the corresponding type slot? All the comparisons eventually end up there anyway, so it seems like the right place to provide a one-stop comparis

Re: [Python-3000] Please re-add __cmp__ to python 3000

2007-10-17 Thread Guido van Rossum
On 10/17/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > I'm having troubles coming up with things where the *basic* operator > is really a cmp-like function. Here's one. When implementing the '<' operator on lists or tuples, you really want to call the 'cmp' operator on the individual items, beca

Re: [Python-3000] Please re-add __cmp__ to python 3000

2007-10-17 Thread Aahz
On Wed, Oct 17, 2007, Steven Bethard wrote: > > I'm having troubles coming up with things where the *basic* operator > is really a cmp-like function. Even in your example, the cmp function > was defined in terms of "less than". If the basic operator is really > "less than", then why define a cmp()

Re: [Python-3000] Please re-add __cmp__ to python 3000

2007-10-17 Thread Steven Bethard
On 10/17/07, David A. Wheeler <[EMAIL PROTECTED]> wrote: > I said: > > I agree with Collin Winter: losing __cmp__ is a loss (see > > http://oakwinter.com/code/). > > Steven Bethard said: > >Why can't this just be supplied with a mixin? Here's a recipe > >providing the appropriate mixins if you w

Re: [Python-3000] Please re-add __cmp__ to python 3000

2007-10-17 Thread Guido van Rossum
On 10/17/07, David A. Wheeler <[EMAIL PROTECTED]> wrote: > I said: > > I agree with Collin Winter: losing __cmp__ is a loss (see > > http://oakwinter.com/code/). > > Steven Bethard said: > >Why can't this just be supplied with a mixin? Here's a recipe > >providing the appropriate mixins if you w

Re: [Python-3000] Please re-add __cmp__ to python 3000

2007-10-17 Thread Adam Hupp
On 10/17/07, David A. Wheeler <[EMAIL PROTECTED]> wrote: > class NumberMixinCmp(ComparisonMixin): ... > def cmp(self, other): > if self.x == other.x: return 0 > return (-1 if self.x < other.x else 1) In the common case the == test will be false. About ~1/2 of the tests will b

Re: [Python-3000] Please re-add __cmp__ to python 3000

2007-10-17 Thread David A. Wheeler
I said: > I did a test (see below), and the mixin using a simulated cmp took > 50% MORE time to sort a list using Python 2.5 (see code below) than > when __cmp__ is used directly (as you CAN do in Python 2.5). Oops, I forgot to post the actual numbers. Here they are, on my box (your mileage will

Re: [Python-3000] Please re-add __cmp__ to python 3000

2007-10-17 Thread David A. Wheeler
I said: > I agree with Collin Winter: losing __cmp__ is a loss (see > http://oakwinter.com/code/). Steven Bethard said: >Why can't this just be supplied with a mixin? Here's a recipe >providing the appropriate mixins if you want to define a __key__ >function: >http://aspn.activestate.com/AS