Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Antoon Pardon
I was wondering how people would feel if the cmp function and the __cmp__ method would be a bit more generalised. The problem now is that the cmp protocol has no way to indicate two objects are incomparable, they are not equal but neither is one less or greater than the other. So I thought that e

Re: Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Duncan Booth
Antoon Pardon wrote: > The problem now is that the cmp protocol has no way to > indicate two objects are incomparable, they are not > equal but neither is one less or greater than the other. If that is the case then you implement __eq__ and __ne__ to return True/False and make cmp throw an excep

Re: Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Antoon Pardon
Op 2005-10-20, Duncan Booth schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: > >> The problem now is that the cmp protocol has no way to >> indicate two objects are incomparable, they are not >> equal but neither is one less or greater than the other. > > If that is the case then you implement _

Re: Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Duncan Booth
Antoon Pardon wrote: > Op 2005-10-20, Duncan Booth schreef <[EMAIL PROTECTED]>: >> Antoon Pardon wrote: >> >>> The problem now is that the cmp protocol has no way to >>> indicate two objects are incomparable, they are not >>> equal but neither is one less or greater than the other. >> >> If that i

Re: Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Mikael Olofsson
Antoon Pardon wrote: > Op 2005-10-20, Duncan Booth schreef <[EMAIL PROTECTED]>: > >>Antoon Pardon wrote: >> >> >>>The problem now is that the cmp protocol has no way to >>>indicate two objects are incomparable, they are not >>>equal but neither is one less or greater than the other. >> >>If that i

Re: Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Antoon Pardon
Op 2005-10-20, Mikael Olofsson schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> Op 2005-10-20, Duncan Booth schreef <[EMAIL PROTECTED]>: >> >>>Antoon Pardon wrote: >>> >>> The problem now is that the cmp protocol has no way to indicate two objects are incomparable, they are not e

Re: Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Steve Holden
Antoon Pardon wrote: > I was wondering how people would feel if the cmp function and > the __cmp__ method would be a bit more generalised. > > The problem now is that the cmp protocol has no way to > indicate two objects are incomparable, they are not > equal but neither is one less or greater tha

Re: Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Antoon Pardon
Op 2005-10-20, Steve Holden schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> I was wondering how people would feel if the cmp function and >> the __cmp__ method would be a bit more generalised. >> >> The problem now is that the cmp protocol has no way to >> indicate two objects are incompara

Re: Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Toby Dickenson
On Thursday 20 October 2005 11:53, Steve Holden wrote: > Personally I'm still not convinced that your requirement reflects a > substantial use case (but then I'm getting used to that ;-). Just > because an ordering is partial that doesn't mean that two instances of a > class shouldn't be compar

Re: Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Steve Holden
Antoon Pardon wrote: > Op 2005-10-20, Steve Holden schreef <[EMAIL PROTECTED]>: > >>Antoon Pardon wrote: >> >>>I was wondering how people would feel if the cmp function and >>>the __cmp__ method would be a bit more generalised. >>> >>>The problem now is that the cmp protocol has no way to >>>indic

Re: Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Tim Peters
[Toby Dickenson] > ... > ZODB's BTrees work in a similar way but use the regular python comparison > function, and the lack of a guarantee of a total ordering can be a liability. > Described here in 2002, but I think same is true today: > http://mail.zope.org/pipermail/zodb-dev/2002-February/002304

Re: Would there be support for a more general cmp/__cmp__

2005-10-21 Thread Antoon Pardon
Op 2005-10-20, Steve Holden schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> > Ergo: use rich comparisons. rich comparosons can only solve the problem partly. Python does have the cmp function and that can give totaly inconsistent results even when the order defined by the rich comparison

Re: Would there be support for a more general cmp/__cmp__

2005-10-21 Thread Christopher Subich
Antoon Pardon wrote: > It would be better if cmp would give an indication it > can't compare two objects instead of giving incorrect > and inconsistent results. If two objects aren't totally comparable, then using 'cmp' on them is ill-defined to begin with. The Standard Thing To Do is throw an

Re: Would there be support for a more general cmp/__cmp__

2005-10-24 Thread Antoon Pardon
Op 2005-10-21, Christopher Subich schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> It would be better if cmp would give an indication it >> can't compare two objects instead of giving incorrect >> and inconsistent results. > > If two objects aren't totally comparable, then using 'cmp' on them

Re: Would there be support for a more general cmp/__cmp__

2005-10-24 Thread Steve Holden
Antoon Pardon wrote: > Op 2005-10-21, Christopher Subich schreef <[EMAIL PROTECTED]>: > >>Antoon Pardon wrote: >> >>>It would be better if cmp would give an indication it >>>can't compare two objects instead of giving incorrect >>>and inconsistent results. >> >>If two objects aren't totally compar

Re: Would there be support for a more general cmp/__cmp__

2005-10-24 Thread Antoon Pardon
Op 2005-10-24, Steve Holden schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> >set([1]) <= set([2]) >> >> False >> >set([2]) <= set([1]) >> >> False >> > Set orderingd are explicitly documented as being based on proper > subsetting. This is an abuse of the operators to make subs

Re: Would there be support for a more general cmp/__cmp__

2005-10-24 Thread Steven D'Aprano
On Mon, 24 Oct 2005 09:23:58 +, Antoon Pardon wrote: > Op 2005-10-21, Christopher Subich schreef <[EMAIL PROTECTED]>: >> Antoon Pardon wrote: >>> It would be better if cmp would give an indication it >>> can't compare two objects instead of giving incorrect >>> and inconsistent results. >> >>

Re: Would there be support for a more general cmp/__cmp__

2005-10-24 Thread Antoon Pardon
Op 2005-10-24, Steven D'Aprano schreef <[EMAIL PROTECTED]>: > On Mon, 24 Oct 2005 09:23:58 +, Antoon Pardon wrote: > >> Op 2005-10-21, Christopher Subich schreef <[EMAIL PROTECTED]>: >>> Antoon Pardon wrote: It would be better if cmp would give an indication it can't compare two objec

Re: Would there be support for a more general cmp/__cmp__

2005-10-24 Thread James Stroud
On Monday 24 October 2005 04:33, Steve Holden wrote: > Well in that case it's time to declare Principia Mathematica obsolete. > The real numbers are a two-dimensional field, and you are proposing to > define an ordering for it. I wasn't a math major, but don't you mean "the complex numbers are a t

Re: Would there be support for a more general cmp/__cmp__

2005-10-24 Thread Steve Holden
James Stroud wrote: > On Monday 24 October 2005 04:33, Steve Holden wrote: > >>Well in that case it's time to declare Principia Mathematica obsolete. >>The real numbers are a two-dimensional field, and you are proposing to >>define an ordering for it. > > > I wasn't a math major, but don't you m

Re: Would there be support for a more general cmp/__cmp__

2005-10-25 Thread Christopher Subich
Antoon Pardon wrote: > It *is* a definition of an ordering. > > For something to be an ordering it has to be anti symmetric and transitive. > > The subset relationships on sets conform to these conditions so it is a > (partial) > ordering. Check your mathematic books, Why you would think this is

Re: Would there be support for a more general cmp/__cmp__

2005-10-25 Thread Christopher Subich
Antoon Pardon wrote: > I also think there is the problem that people aren't used to partial > ordering. There is an ordering over sets, it is just not a total > ordering. But that some pairs are uncomparable (meaning that neither > one is smaller or greater) doesn't imply that comparing them is >

Re: Would there be support for a more general cmp/__cmp__

2005-10-25 Thread Antoon Pardon
Op 2005-10-25, Christopher Subich schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> It *is* a definition of an ordering. >> >> For something to be an ordering it has to be anti symmetric and transitive. >> >> The subset relationships on sets conform to these conditions so it is a >> (partia

Re: Would there be support for a more general cmp/__cmp__

2005-10-25 Thread Steven D'Aprano
On Tue, 25 Oct 2005 10:09:29 -0400, Christopher Subich wrote: >>>By analogy, one can ask, "is the cat inside the box?" and get the answer >>>"No", but this does not imply that therefore the box must be inside the >>>cat. >> >> >> Bad analogy, this doesn't define a mathematical ordering, the subs

Re: Would there be support for a more general cmp/__cmp__

2005-10-25 Thread Christopher Subich
Antoon Pardon wrote: > Op 2005-10-25, Christopher Subich schreef <[EMAIL PROTECTED]>: > >>Which is exactly why a < b on sets returns True xor False, but cmp(a,b) >>throws an exception. > > > I don't see the conection. > > The documentation states that cmp(a,b) will return a negative value if

Re: Would there be support for a more general cmp/__cmp__

2005-10-25 Thread Steve Holden
Steven D'Aprano wrote: > On Tue, 25 Oct 2005 10:09:29 -0400, Christopher Subich wrote: > > By analogy, one can ask, "is the cat inside the box?" and get the answer "No", but this does not imply that therefore the box must be inside the cat. >>> >>> >>>Bad analogy, this doesn't define

Re: Would there be support for a more general cmp/__cmp__

2005-10-26 Thread Antoon Pardon
Op 2005-10-25, Christopher Subich schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> Op 2005-10-25, Christopher Subich schreef <[EMAIL PROTECTED]>: >> > >>>Which is exactly why a < b on sets returns True xor False, but cmp(a,b) >>>throws an exception. >> >> >> I don't see the conection. >>

Re: Would there be support for a more general cmp/__cmp__

2005-10-26 Thread Antoon Pardon
Op 2005-10-25, Christopher Subich schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: > >> I also think there is the problem that people aren't used to partial >> ordering. There is an ordering over sets, it is just not a total >> ordering. But that some pairs are uncomparable (meaning that neither

Re: Would there be support for a more general cmp/__cmp__

2005-10-26 Thread Antoon Pardon
Op 2005-10-25, Steven D'Aprano schreef <[EMAIL PROTECTED]>: > On Tue, 25 Oct 2005 10:09:29 -0400, Christopher Subich wrote: > By analogy, one can ask, "is the cat inside the box?" and get the answer "No", but this does not imply that therefore the box must be inside the cat. >>> >>> >

Re: Would there be support for a more general cmp/__cmp__

2005-10-26 Thread Ron Adam
Antoon Pardon wrote: > Op 2005-10-25, Steven D'Aprano schreef <[EMAIL PROTECTED]>: >>Can somebody remind me, what is the problem Antoon is trying to solve here? > > > Well there are two issues. One about correct behaviour and one about > practicallity. > > The first problem is cmp. This is w

Re: Would there be support for a more general cmp/__cmp__

2005-10-26 Thread Christopher Subich
Antoon Pardon wrote: > Op 2005-10-25, Christopher Subich schreef <[EMAIL PROTECTED]>: >> >>My biggest complaint here is about returning None or IncomparableValue; >>if that happens, then all code that relies on cmp returning a numeric >>result will have to be rewritten. > > > I don't know. Ther

Re: Would there be support for a more general cmp/__cmp__

2005-10-26 Thread Steven Bethard
Antoon Pardon wrote: > Christopher Subich schreef : > >> Antoon Pardon wrote: >>> >>>from decimal import Decimal >>> >>>Zero = Decimal(0) >>> >>>cmp( ( ) , Zero) >>> -1 >>> >>>cmp(Zero, 1) >>> -1 >>> >>>cmp(1, ( ) ) >>> -1 >> >> I'd argue that the wart here is that cmp doesn't throw an exception,

Re: Would there be support for a more general cmp/__cmp__

2005-10-27 Thread Antoon Pardon
Op 2005-10-26, Ron Adam schreef <[EMAIL PROTECTED]>: > > > Antoon Pardon wrote: > >> Op 2005-10-25, Steven D'Aprano schreef <[EMAIL PROTECTED]>: > >>>Can somebody remind me, what is the problem Antoon is trying to solve here? >> >> >> Well there are two issues. One about correct behaviour and one

Re: Would there be support for a more general cmp/__cmp__

2005-10-27 Thread Antoon Pardon
Op 2005-10-26, Christopher Subich schreef <[EMAIL PROTECTED]>: > Antoon Pardon wrote: >> Op 2005-10-25, Christopher Subich schreef <[EMAIL PROTECTED]>: >>> >>>My biggest complaint here is about returning None or IncomparableValue; >>>if that happens, then all code that relies on cmp returning a nu

Re: Would there be support for a more general cmp/__cmp__

2005-10-27 Thread Bengt Richter
On 27 Oct 2005 08:12:15 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote: [...] > >The evidence suggests that cmp is not used in sorting. If you have a >list of sets, sort will happily try to sort it, while calling cmp >with a set as an argument throws an exception. > A data point re evidence: >>> cl

Re: Would there be support for a more general cmp/__cmp__

2005-10-28 Thread Antoon Pardon
Op 2005-10-26, Ron Adam schreef <[EMAIL PROTECTED]>: > > Adding complexity to cmp may not break code, but it could probably slow > down sorting in general. So I would think what ever improvements or > alternatives needs to be careful not to slow down existing sorting cases. As a result of Bengt

Re: Would there be support for a more general cmp/__cmp__

2005-10-28 Thread Antoon Pardon
Op 2005-10-28, Antoon Pardon schreef <[EMAIL PROTECTED]>: > Op 2005-10-26, Ron Adam schreef <[EMAIL PROTECTED]>: >> > > These are the results. > >: 1000 repeats, 1000 long, 10.061425 secs >: 1000 repeats, 1000 long, 9.544035 secs >: 1000 repeats, 1000 long, 10.450864 secs >: 1000 repeats, 1000 lon

Re: Would there be support for a more general cmp/__cmp__

2005-10-28 Thread Ron Adam
Antoon Pardon wrote: > Op 2005-10-26, Ron Adam schreef <[EMAIL PROTECTED]>: > >>Adding complexity to cmp may not break code, but it could probably slow >>down sorting in general. So I would think what ever improvements or >>alternatives needs to be careful not to slow down existing sorting ca

Re: Would there be support for a more general cmp/__cmp__

2005-10-28 Thread Christopher Subich
Antoon Pardon wrote: > If you are concerned about sorting times, I think you should > be more concerned about Guido's idea of doing away with __cmp__. > Sure __lt__ is faster. But in a number of cases writing __cmp__ > is of the same complexity as writing __lt__. So if you then > need a __lt__, __l

Re: Would there be support for a more general cmp/__cmp__

2005-10-31 Thread Antoon Pardon
Op 2005-10-28, Ron Adam schreef <[EMAIL PROTECTED]>: > > I haven't heard he was removing __cmp__, I read somewhere he was considering it. > but I would think the sort or > sorted functions would just use the available comparisons methods or > equivalent C code for base types. So I expect it wo