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

2007-11-19 Thread Nick Coghlan
Jeffrey Yasskin wrote: > For Python, I think I favor reviving __cmp__ for totally ordered > types, and asking that partially ordered ones return NotImplemented > from it explicitly. Returning NotImplemented already means "I don't recognise the other type". A fully implemented partial ordering is

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

2007-11-19 Thread Jim Jewett
On 11/17/07, Greg Ewing <[EMAIL PROTECTED]> wrote: > Martin v. Löwis wrote: > > or __cmp__ would > > have to be extended to support "unordered" as a result. > > That's what I think should be done. Note that this would make it slightly easier to pass a custom sort function that forced everything to

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

2007-11-17 Thread Greg Ewing
Martin v. Löwis wrote: > or __cmp__ would > have to be extended to support "unordered" as a result. That's what I think should be done. -- Greg ___ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsub

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

2007-11-17 Thread Martin v. Löwis
> It'd be simpler still if we only had __cmp__ and __eq__. I just don't > understand the use cases where that's not sufficient. > > Hrm. I guess set's subset checking requires more relationships than > __cmp__ provides. Abandoning that feature probably isn't an option, > so nevermind me. > > (

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

2007-11-03 Thread Brett Cannon
On 11/3/07, Guido van Rossum <[EMAIL PROTECTED]> wrote: > Everyone who cares about this topic, please collaborate on a PEP. If > we're going to put __cmp__ back in I'd like to have it in 3.0a2 if at > all possible. I'd like to release 3.0a2 around mid November. I don't > personally have much time t

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

2007-11-03 Thread Guido van Rossum
Everyone who cares about this topic, please collaborate on a PEP. If we're going to put __cmp__ back in I'd like to have it in 3.0a2 if at all possible. I'd like to release 3.0a2 around mid November. I don't personally have much time to devote to the topic, but I've seen some pretty well-motivated

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

2007-10-30 Thread Adam Olsen
On 10/30/07, Greg Ewing <[EMAIL PROTECTED]> wrote: > Adam Olsen wrote: > > for a, b in zip(self.data, other.data): > > result = richcmp(a, b, ordered) > > if result: > > return result > > That can't be right, because there are *three*

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

2007-10-30 Thread Greg Ewing
Steven Bethard wrote: > If a class defines only __cmp__, Python will do the appropriate > dance to make <, >, ==, etc. work right. If a class defines only > __eq__, __lt__, etc. Python will do the appropriate dance to make > cmp() work right. With a four-way __cmp__, I wouldn't actually mind if t

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

2007-10-30 Thread Greg Ewing
Adam Olsen wrote: > for a, b in zip(self.data, other.data): > result = richcmp(a, b, ordered) > if result: > return result That can't be right, because there are *three* possible results you need to be able to distinguish from compari

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

2007-10-30 Thread Greg Ewing
Steven Bethard wrote: > class C(object): > def __cmp__(self, other): > if self.foo < other.foo: > return -1 > elif self.foo < other.foo: > return 1 > else: > return 0 With __cmp__, in cases like that yo

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

2007-10-30 Thread Steven Bethard
On 10/30/07, Adam Olsen <[EMAIL PROTECTED]> wrote: > > I'm actually currently in favor of keeping __cmp__ as it is in Python > > 2.5. If a class defines only __cmp__, Python will do the appropriate > > dance to make <, >, ==, etc. work right. If a class defines only > > __eq__, __lt__, etc. Pytho

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

2007-10-30 Thread Adam Olsen
On 10/30/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > On 10/30/07, Adam Olsen <[EMAIL PROTECTED]> wrote: > > On 10/30/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > > > On 10/30/07, Adam Olsen <[EMAIL PROTECTED]> wrote: > > > > cmp and __cmp__ are doomed, due to unorderable types now raising >

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

2007-10-30 Thread Steven Bethard
On 10/30/07, Adam Olsen <[EMAIL PROTECTED]> wrote: > On 10/30/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > > On 10/30/07, Adam Olsen <[EMAIL PROTECTED]> wrote: > > > cmp and __cmp__ are doomed, due to unorderable types now raising > > > exceptions: > > > > > > >>> cmp(3, 'hello') > > > Tracebac

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

2007-10-30 Thread Adam Olsen
On 10/30/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > On 10/30/07, Adam Olsen <[EMAIL PROTECTED]> wrote: > > cmp and __cmp__ are doomed, due to unorderable types now raising exceptions: > > > > >>> cmp(3, 'hello') > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: u

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

2007-10-30 Thread Steven Bethard
On 10/30/07, Adam Olsen <[EMAIL PROTECTED]> wrote: > cmp and __cmp__ are doomed, due to unorderable types now raising exceptions: > > >>> cmp(3, 'hello') > Traceback (most recent call last): > File "", line 1, in > TypeError: unorderable types: int() < str() > >>> 3 == 'hello' > False > > A mixi

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

2007-10-30 Thread Adam Olsen
On 10/30/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > On 10/30/07, Adam Olsen <[EMAIL PROTECTED]> wrote: > > It's clear to me that the opposition to removing __cmp__ comes down to > > "make the common things easy and the rare things possible". Removing > > __cmp__ means one of the common things

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

2007-10-30 Thread Steven Bethard
On 10/30/07, Adam Olsen <[EMAIL PROTECTED]> wrote: > It's clear to me that the opposition to removing __cmp__ comes down to > "make the common things easy and the rare things possible". Removing > __cmp__ means one of the common things (total ordering) becomes hard. I don't really think that's it

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

2007-10-30 Thread Adam Olsen
On 10/30/07, Greg Ewing <[EMAIL PROTECTED]> wrote: > Adam Olsen wrote: > > It'd be simpler still if we only had __cmp__ and __eq__. I just don't > > understand the use cases where that's not sufficient. > > > > Hrm. I guess set's subset checking requires more relationships than > > __cmp__ provid

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

2007-10-30 Thread Greg Ewing
Adam Olsen wrote: > It'd be simpler still if we only had __cmp__ and __eq__. I just don't > understand the use cases where that's not sufficient. > > Hrm. I guess set's subset checking requires more relationships than > __cmp__ provides. Also, you might want to give the comparison operators mea

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

2007-10-29 Thread Jeffrey Yasskin
On 10/29/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > On 10/29/07, David A. Wheeler <[EMAIL PROTECTED]> wrote: > > I think several postings have explained better than I have on why __cmp__ > > is still very valuable. (See below.) > > > > Guido van Rossum posted earlier that he was willing to e

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

2007-10-29 Thread Adam Olsen
On 10/29/07, Greg Ewing <[EMAIL PROTECTED]> wrote: > Adam Olsen wrote: > > It's not clear to me how many distinct operations you'd need though, > > or how acceptable reflections would be. > > My intention was just to directly expose the tp_richcmp > slot, so there would be six. > > To make things e

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

2007-10-29 Thread Greg Ewing
Adam Olsen wrote: > It's not clear to me how many distinct operations you'd need though, > or how acceptable reflections would be. My intention was just to directly expose the tp_richcmp slot, so there would be six. To make things easier in the common case, there could perhaps be a utility functi

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

2007-10-29 Thread Guido van Rossum
2007/10/29, Greg Ewing <[EMAIL PROTECTED]>: > David A. Wheeler wrote: > > Greg Ewing stated "Why not provide a __richcmp__ method that > > directly connects with the corresponding type slot? > > > It _seems_ to me that this is the same as "__cmp__", > > No, it's not -- a __richcmp__ method would ta

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

2007-10-29 Thread Greg Ewing
David A. Wheeler wrote: > Greg Ewing stated "Why not provide a __richcmp__ method that directly connects > with the corresponding type slot? > It _seems_ to me that this is the same as "__cmp__", No, it's not -- a __richcmp__ method would take an extra argument specifying which of the six compari

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

2007-10-29 Thread Guido van Rossum
I'm a bit too busy to look into this right now; I hope one or two more rounds of feedback on the PEP will get it into a state where I can review it more easily. Having a patch to go with it would be immensely helpful as well (in fact I'd say that without a patch it's unlikely to happen). --Guido

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

2007-10-29 Thread Steven Bethard
On 10/29/07, David A. Wheeler <[EMAIL PROTECTED]> wrote: > I think several postings have explained better than I have on why __cmp__ is > still very valuable. (See below.) > > Guido van Rossum posted earlier that he was willing to entertain a PEP to > restore __cmp__, so I've attempted to create

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

2007-10-29 Thread Adam Olsen
On 10/29/07, David A. Wheeler <[EMAIL PROTECTED]> wrote: > I think several postings have explained better than I have on why __cmp__ is > still very valuable. (See below.) > > Guido van Rossum posted earlier that he was willing to entertain a PEP to > restore __cmp__, so I've attempted to create

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

2007-10-29 Thread David A. Wheeler
I think several postings have explained better than I have on why __cmp__ is still very valuable. (See below.) Guido van Rossum posted earlier that he was willing to entertain a PEP to restore __cmp__, so I've attempted to create a draft PEP, posted here: http://www.dwheeler.com/misc/pep-cmp.

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

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

2007-10-16 Thread Guido van Rossum
On 10/16/07, David A. Wheeler <[EMAIL PROTECTED]> wrote: > I agree with Collin Winter: losing __cmp__ is a loss (see > http://oakwinter.com/code/). > > Yes, it's possible to write all the comparison operations, but I think it's > _clearer_ to create a single low-level operator that handles ALL t

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

2007-10-16 Thread Steven Bethard
On 10/16/07, David A. Wheeler <[EMAIL PROTECTED]> wrote: > I agree with Collin Winter: losing __cmp__ is a loss (see > http://oakwinter.com/code/). > > Yes, it's possible to write all the comparison operations, but I think > it's _clearer_ to create a single low-level operator that handles ALL >