Re: WAT: opCmp and opEquals woes

2014-10-15 Thread Martin Nowak via Digitalmars-d
On Wednesday, 23 July 2014 at 21:14:35 UTC, Brian Schott wrote: $ ./dscanner --styleCheck ~/tmp/test.d test.d(1:8)[warn]: 'A' has method 'opCmp', but not 'opEquals'. Nice

Re: WAT: opCmp and opEquals woes

2014-10-15 Thread Marco Leise via Digitalmars-d
Am Wed, 15 Oct 2014 11:25:10 + schrieb Martin Nowak c...@dawg.eu: On Wednesday, 23 July 2014 at 21:14:35 UTC, Brian Schott wrote: $ ./dscanner --styleCheck ~/tmp/test.d test.d(1:8)[warn]: 'A' has method 'opCmp', but not 'opEquals'. Nice Yep! Some say opCmp is something entirely

Re: WAT: opCmp and opEquals woes

2014-08-16 Thread Fool via Digitalmars-d
On Wednesday, 23 July 2014 at 21:36:16 UTC, Andrei Alexandrescu wrote: There is this notion of partial ordering that makes objects not smaller and not greater than others, yet not equal. -- Andrei How do you define a partial ordering using opCmp?

Re: WAT: opCmp and opEquals woes

2014-08-16 Thread deadalnix via Digitalmars-d
On Friday, 25 July 2014 at 22:29:30 UTC, Walter Bright wrote: On 7/25/2014 2:55 PM, Jonathan M Davis wrote: Doesn't the compiler-generated opEquals do a memcmp when it can? Yes. And even sometime when it cannot :D (floats for instance).

Re: WAT: opCmp and opEquals woes

2014-07-28 Thread Fool via Digitalmars-d
On Sunday, 27 July 2014 at 21:16:52 UTC, Ola Fosheim Grøstad wrote: But I thought it was confirmed in this thread by the language designers that == is equality in D, thus === in other languages are not needed? For me two instances of a class located at different memory locations can never be

Re: WAT: opCmp and opEquals woes

2014-07-28 Thread Fool via Digitalmars-d
On Monday, 28 July 2014 at 00:23:36 UTC, H. S. Teoh via Digitalmars-d wrote: On Sun, Jul 27, 2014 at 07:04:08PM +, Fool via Defining opEquals only makes sense if a user wants to replace equality by some equivalence relation (different from equality). Not necessarily. The user type may be

Re: WAT: opCmp and opEquals woes

2014-07-28 Thread Ola Fosheim Gr via Digitalmars-d
On Monday, 28 July 2014 at 06:05:03 UTC, Fool wrote: So D has to separate opEquals and opCmp since otherwise a user could not define floating-point 'equality' and 'comparison' himself in the same way as it is defined by the language. I'm convinced know. :-) But opCmp does not affect and !,

Re: WAT: opCmp and opEquals woes

2014-07-28 Thread via Digitalmars-d
On Monday, 28 July 2014 at 00:23:36 UTC, H. S. Teoh via Digitalmars-d wrote: On Sun, Jul 27, 2014 at 07:04:08PM +, Fool via Digitalmars-d wrote: Similarly, the user is free to define opCmp without restriction. In practice, however, it does not seem to make any sense if = does not even

Re: WAT: opCmp and opEquals woes

2014-07-28 Thread Regan Heath via Digitalmars-d
On Sat, 26 Jul 2014 05:22:26 +0100, Walter Bright newshou...@digitalmars.com wrote: If you don't want to accept that equality and comparison are fundamentally different operations, I can only repeat saying the same things. For the majority of use cases they are *not* in fact fundamentally

Re: WAT: opCmp and opEquals woes

2014-07-28 Thread Regan Heath via Digitalmars-d
On Fri, 25 Jul 2014 21:38:33 +0100, Walter Bright newshou...@digitalmars.com wrote: On 7/25/2014 4:10 AM, Regan Heath wrote: Sure, Andrei makes a valid point .. for a minority of cases. The majority case will be that opEquals and opCmp==0 will agree. In those minority cases where they

Re: WAT: opCmp and opEquals woes

2014-07-28 Thread Don via Digitalmars-d
On Monday, 28 July 2014 at 06:05:03 UTC, Fool wrote: On Monday, 28 July 2014 at 00:23:36 UTC, H. S. Teoh via Digitalmars-d wrote: On Sun, Jul 27, 2014 at 07:04:08PM +, Fool via Defining opEquals only makes sense if a user wants to replace equality by some equivalence relation (different

Re: WAT: opCmp and opEquals woes

2014-07-28 Thread via Digitalmars-d
On Monday, 28 July 2014 at 09:37:27 UTC, Regan Heath wrote: My point was that for the vast majority of coders, in the vast majority of cases opCmp()==0 will agree with opEquals(). It is only in very niche cases i.e. where partial ordering is actually present and important, that this

Re: WAT: opCmp and opEquals woes

2014-07-28 Thread Iain Buclaw via Digitalmars-d
On 26 July 2014 00:31, Walter Bright via Digitalmars-d digitalmars-d@puremagic.com wrote: On 7/25/2014 4:28 PM, H. S. Teoh via Digitalmars-d wrote: That page doesn't say anything about TypeInfo, though. It says to follow the form. But even then, why doesn't the compiler reject opCmp

Re: WAT: opCmp and opEquals woes

2014-07-28 Thread Timon Gehr via Digitalmars-d
On 07/23/2014 06:45 PM, H. S. Teoh via Digitalmars-d wrote: This morning, I discovered this major WAT in D: struct S { int x; int y; int opCmp(S s) { return x - s.x; // compare only x } } ... Not even transitive! void main() {

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread Andrei Alexandrescu via Digitalmars-d
On 7/26/14, 7:58 PM, Manu via Digitalmars-d wrote: On 26 July 2014 19:48, Andrei Alexandrescu via Digitalmars-d digitalmars-d@puremagic.com mailto:digitalmars-d@puremagic.com wrote: On 7/26/14, 2:19 AM, Marc Schütz schue...@gmx.net mailto:schue...@gmx.net wrote: On Saturday, 26

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread via Digitalmars-d
In order to get an overview for myself I've summarized the various properties of different types of orders as they are described in Wikipedia (right or wrong). I post it here in case others have an interest in it (or corrections/extensions to it): * Preorder: a ≤ a (reflexivity) if a ≤ b

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread via Digitalmars-d
On Sunday, 27 July 2014 at 13:06:23 UTC, Ola Fosheim Grøstad wrote: * Total Preorder: x ≲ b or b ≲ a (totality). if a ≲ b and b ≲ c then a ≲ c (transitivity). x ≲ b (reflexivity; implied by transitivity and totality) Correction: * Total Preorder: a ≲ b or b ≲ a (totality). if a ≲ b and b

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread via Digitalmars-d
On Saturday, 26 July 2014 at 16:43:06 UTC, Fool wrote: NaN x is false NaN x is false ...which means that as it is usually defined on floating point numbers does not define a strict weak ordering. Are you sure? Properties of a Strict Weak Ordering: #1 not(a a) #2 not(a b and b c) or

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread Fool via Digitalmars-d
On Sunday, 27 July 2014 at 16:39:01 UTC, Ola Fosheim Grøstad wrote: On Saturday, 26 July 2014 at 16:43:06 UTC, Fool wrote: NaN x is false NaN x is false ...which means that as it is usually defined on floating point numbers does not define a strict weak ordering. Are you sure? One can

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread Ola Fosheim Gr via Digitalmars-d
On Sunday, 27 July 2014 at 18:00:29 UTC, Fool wrote: Thus we do not have transitivity of incomparability: You are right, I forgot to test the case where only c is NaN. Well, that makes floats suck even more! :-)

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread Fool via Digitalmars-d
On Sunday, 27 July 2014 at 00:43:40 UTC, H. S. Teoh via Digitalmars-d wrote: https://github.com/D-Programming-Language/dlang.org/pull/620 Thank you for this. There is still a problem, I think. Defining opEquals only makes sense if a user wants to replace equality by some equivalence

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread Fool via Digitalmars-d
On Sunday, 27 July 2014 at 18:22:50 UTC, Ola Fosheim Gr wrote: On Sunday, 27 July 2014 at 18:00:29 UTC, Fool wrote: Thus we do not have transitivity of incomparability: You are right, I forgot to test the case where only c is NaN. Well, that makes floats suck even more! :-) In fact, IEEE

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread Fool via Digitalmars-d
On Sunday, 27 July 2014 at 19:04:09 UTC, Fool wrote: define ~ such that a ~ b = (a = b or b = a) ^^ and, of course What should I say, I'm a fool... ;-)

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread Walter Bright via Digitalmars-d
On 7/26/2014 9:46 AM, H. S. Teoh via Digitalmars-d wrote: On Fri, Jul 25, 2014 at 11:27:57PM -0700, Walter Bright via Digitalmars-d wrote: I welcome a PR from you on this! https://github.com/D-Programming-Language/dlang.org/pull/620 Thanks!

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread via Digitalmars-d
On Sunday, 27 July 2014 at 19:04:09 UTC, Fool wrote: If a candidate for opCmp does not match the default equivalence relation == (defined implicitly or explicitly specified using opEquals) it should not be defined at all. Does this mean that you agree that opCmp should define a total order?

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread Fool via Digitalmars-d
On Sunday, 27 July 2014 at 20:45:25 UTC, Ola Fosheim Grøstad wrote: On Sunday, 27 July 2014 at 19:04:09 UTC, Fool wrote: If a candidate for opCmp does not match the default equivalence relation == (defined implicitly or explicitly specified using opEquals) it should not be defined at all.

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread Fool via Digitalmars-d
I think that some confusion is due to == is regarded as meaning equality while it only means equivalence. Modifying the RGB color example: there is a natural order on the red channel. Given this ordering, two RGB colors are equivalent if and only if their red values coincide. In this sense,

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread via Digitalmars-d
On Sunday, 27 July 2014 at 21:07:08 UTC, Fool wrote: I think that some confusion is due to == is regarded as meaning equality while it only means equivalence. But I thought it was confirmed in this thread by the language designers that == is equality in D, thus === in other languages are not

Re: WAT: opCmp and opEquals woes

2014-07-27 Thread H. S. Teoh via Digitalmars-d
On Sun, Jul 27, 2014 at 07:04:08PM +, Fool via Digitalmars-d wrote: On Sunday, 27 July 2014 at 00:43:40 UTC, H. S. Teoh via Digitalmars-d wrote: https://github.com/D-Programming-Language/dlang.org/pull/620 Thank you for this. There is still a problem, I think. Defining opEquals only

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread H. S. Teoh via Digitalmars-d
On Fri, Jul 25, 2014 at 09:22:26PM -0700, Walter Bright via Digitalmars-d wrote: On 7/25/2014 8:41 PM, Manu via Digitalmars-d wrote: [...] It may be correct, if you're lucky, and that's the best offer you'll get. opCmp==0 however is practically certain to be correct, since = and = are

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread H. S. Teoh via Digitalmars-d
On Sat, Jul 26, 2014 at 01:47:20PM +1000, Manu via Digitalmars-d wrote: On 26 July 2014 06:35, Walter Bright via Digitalmars-d digitalmars-d@puremagic.com wrote: [...] So perhaps === is missing, and that's what should be used for AA's, and also the thing that actually matches the compiler's

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread Walter Bright via Digitalmars-d
On 7/25/2014 11:05 PM, H. S. Teoh via Digitalmars-d wrote: Well, we can argue about this until the cows come home, but at least for the present regression being addressed, I think Jonathan's fix is the best option (or the least of all evils): revert the compiler change that causes a compile

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread Walter Bright via Digitalmars-d
On 7/25/2014 10:40 PM, H. S. Teoh via Digitalmars-d wrote: On Fri, Jul 25, 2014 at 06:44:36PM -0700, Andrei Alexandrescu via Digitalmars-d wrote: I think we should remove the breakage introduced by requiring opEquals if opCmp is defined. It breaks good code for no good reason. Yes, we should

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread Manu via Digitalmars-d
On 26 July 2014 16:13, H. S. Teoh via Digitalmars-d digitalmars-d@puremagic.com wrote: On Sat, Jul 26, 2014 at 01:47:20PM +1000, Manu via Digitalmars-d wrote: On 26 July 2014 06:35, Walter Bright via Digitalmars-d digitalmars-d@puremagic.com wrote: [...] So perhaps === is missing, and

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread via Digitalmars-d
On Saturday, 26 July 2014 at 06:50:11 UTC, Manu via Digitalmars-d wrote: It's okay, I hate it too. But I equally can't abide == meaning something different than , =, etc. That's insane. Yes, it is unsound to use opCmp for types that aren't totally ordered:

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread via Digitalmars-d
On Saturday, 26 July 2014 at 07:42:05 UTC, Ola Fosheim Grøstad wrote: On Saturday, 26 July 2014 at 06:50:11 UTC, Manu via Digitalmars-d wrote: It's okay, I hate it too. But I equally can't abide == meaning something different than , =, etc. That's insane. Yes, it is unsound to use opCmp for

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread Andrei Alexandrescu via Digitalmars-d
On 7/26/14, 2:19 AM, Marc Schütz schue...@gmx.net wrote: On Saturday, 26 July 2014 at 07:42:05 UTC, Ola Fosheim Grøstad wrote: On Saturday, 26 July 2014 at 06:50:11 UTC, Manu via Digitalmars-d wrote: It's okay, I hate it too. But I equally can't abide == meaning something different than , =,

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread Fool via Digitalmars-d
I agree that the documentation needs improvement. It needs to be defined what kind of relation opCmp is meant to model. If it's concept is a partial order, opEquals cannot be inferred. If it's concept is a strict weak ordering [1, 2], which is required for sorting, opEqual can be inferred.

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread via Digitalmars-d
On Saturday, 26 July 2014 at 09:48:55 UTC, Andrei Alexandrescu wrote: On 7/26/14, 2:19 AM, Marc Schütz schue...@gmx.net wrote: Yes, that's why it's possible to provide opEquals in addition to opCmp. Not quite, opCmp would then have to throw if opCmp(a,b) is incomparable. Conflating

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread via Digitalmars-d
On Saturday, 26 July 2014 at 10:43:08 UTC, Ola Fosheim Grøstad wrote: On Saturday, 26 July 2014 at 09:48:55 UTC, Andrei Alexandrescu wrote: On 7/26/14, 2:19 AM, Marc Schütz schue...@gmx.net wrote: Yes, that's why it's possible to provide opEquals in addition to opCmp. Not quite, opCmp would

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread via Digitalmars-d
On Saturday, 26 July 2014 at 09:48:55 UTC, Andrei Alexandrescu wrote: On 7/26/14, 2:19 AM, Marc Schütz schue...@gmx.net wrote: On Saturday, 26 July 2014 at 07:42:05 UTC, Ola Fosheim Grøstad wrote: On Saturday, 26 July 2014 at 06:50:11 UTC, Manu via Digitalmars-d wrote: It's okay, I hate it

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread via Digitalmars-d
On Saturday, 26 July 2014 at 12:19:41 UTC, Marc Schütz wrote: I somehow took your response as disagreement with him. No, I think it is useful to have a default total sort order for types even if the order isn't natural and might appear arbitrary. It is useful in binary trees etc. That does

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread via Digitalmars-d
On Saturday, 26 July 2014 at 10:22:54 UTC, Fool wrote: I agree that the documentation needs improvement. It needs to be defined what kind of relation opCmp is meant to model. If it's concept is a partial order, opEquals cannot be inferred. If it's concept is a strict weak ordering [1, 2],

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread Fool via Digitalmars-d
On Saturday, 26 July 2014 at 13:25:06 UTC, Ola Fosheim Grøstad wrote: On Saturday, 26 July 2014 at 10:22:54 UTC, Fool wrote: It needs to be defined what kind of relation opCmp is meant to model. If it's concept is a partial order, opEquals cannot be inferred. If it's concept is a strict

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread H. S. Teoh via Digitalmars-d
On Fri, Jul 25, 2014 at 11:27:57PM -0700, Walter Bright via Digitalmars-d wrote: On 7/25/2014 11:05 PM, H. S. Teoh via Digitalmars-d wrote: [...] In the meantime, I think much of the confusion comes from the current documentation not be adequately clear about the reasoning behind having opCmp

Re: WAT: opCmp and opEquals woes

2014-07-26 Thread Manu via Digitalmars-d
On 26 July 2014 19:48, Andrei Alexandrescu via Digitalmars-d digitalmars-d@puremagic.com wrote: On 7/26/14, 2:19 AM, Marc Schütz schue...@gmx.net wrote: On Saturday, 26 July 2014 at 07:42:05 UTC, Ola Fosheim Grøstad wrote: On Saturday, 26 July 2014 at 06:50:11 UTC, Manu via Digitalmars-d

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jonathan M Davis via Digitalmars-d
On Friday, 25 July 2014 at 04:50:38 UTC, Walter Bright wrote: On 7/23/2014 9:45 AM, H. S. Teoh via Digitalmars-d wrote: https://issues.dlang.org/show_bug.cgi?id=13179 Consider also: http://www.reddit.com/r/programming/comments/2bl51j/programming_in_d_a_great_online_book_for_learning/cj75gm9

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jonathan M Davis via Digitalmars-d
On Friday, 25 July 2014 at 05:52:57 UTC, Manu via Digitalmars-d wrote: On 25 July 2014 14:50, Walter Bright via Digitalmars-d digitalmars-d@puremagic.com wrote: On 7/23/2014 9:45 AM, H. S. Teoh via Digitalmars-d wrote: https://issues.dlang.org/show_bug.cgi?id=13179 Consider also:

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Walter Bright via Digitalmars-d
On 7/24/2014 10:52 PM, Manu via Digitalmars-d wrote: I don't really see how opCmp == 0 could be unreliable or unintended. It was deliberately written by the author, so definitely not unintended, and I can't imagine anybody would ever deliberately ignore the == 0 case when implementing an opCmp,

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jacob Carlborg via Digitalmars-d
On 25/07/14 06:50, Walter Bright wrote: Consider also: http://www.reddit.com/r/programming/comments/2bl51j/programming_in_d_a_great_online_book_for_learning/cj75gm9 The current scheme breaks existing code - code that was formerly correct and working. AAs don't make sense if the notion of ==

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jacob Carlborg via Digitalmars-d
On 25/07/14 08:44, Jonathan M Davis wrote: So, in the case where opCmp was defined but not opEquals, instead of using the normal, built-in opEquals (which should already be equivalent to lhs.opCmp(rhs) == 0), we're going to make the compiler generate opEquals as lhs.opCmp(rhs) == 0? That's a

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jacob Carlborg via Digitalmars-d
On 25/07/14 08:31, Jonathan M Davis wrote: Exactly. The only reason that switching from using lhs.opCmp(rhs) == 0 to opEquals would break code is if a type does not define them such that they're equivalent, which would mean that opEquals and/or opCmp was defined in a buggy manner. So, the only

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jacob Carlborg via Digitalmars-d
On 25/07/14 08:50, Walter Bright wrote: Yes, that's why it's hard to see that it would break existing code, unless that existing code had a bug in it that was worked around in some peculiar way. If the type was only used as an AA key and never checked for equivalent then it worked correctly

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Walter Bright via Digitalmars-d
On 7/25/2014 1:02 AM, Jacob Carlborg wrote: 3. If opCmp is defined but no opEquals, lhs == rhs will be lowered to lhs.opCmp(rhs) == 0 This is the sticking point. opCmp and opEquals are separate on purpose, see Andrei's posts.

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Walter Bright via Digitalmars-d
Putting it simply, 1. == uses opEquals. If you don't supply opEquals, the compiler will make one for you. 2. AAs use ==. See rule 1. Easy to understand, easy to explain, easy to document.

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Walter Bright via Digitalmars-d
On 7/25/2014 1:27 AM, Jacob Carlborg wrote: On 25/07/14 08:50, Walter Bright wrote: Yes, that's why it's hard to see that it would break existing code, unless that existing code had a bug in it that was worked around in some peculiar way. If the type was only used as an AA key and never

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Walter Bright via Digitalmars-d
On 7/25/2014 1:28 AM, Jacob Carlborg wrote: If the type is only used as an AA key and never checked for equivalent it worked when opCmp as used for AA keys. Then we'll just get another bug report from AAs behaving differently from ==.

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jacob Carlborg via Digitalmars-d
On 25/07/14 10:55, Walter Bright wrote: Then we'll just get another bug report from AAs behaving differently from ==. No, not as long as it's not used. -- /Jacob Carlborg

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jacob Carlborg via Digitalmars-d
On 25/07/14 10:48, Walter Bright wrote: Putting it simply, 1. == uses opEquals. If you don't supply opEquals, the compiler will make one for you. 2. AAs use ==. See rule 1. Easy to understand, easy to explain, easy to document. It's very hard to use D when it constantly changes and breaks

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Walter Bright via Digitalmars-d
On 7/25/2014 2:12 AM, Jacob Carlborg wrote: On 25/07/14 10:48, Walter Bright wrote: Putting it simply, 1. == uses opEquals. If you don't supply opEquals, the compiler will make one for you. 2. AAs use ==. See rule 1. Easy to understand, easy to explain, easy to document. It's very hard to

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Walter Bright via Digitalmars-d
On 7/25/2014 2:04 AM, Jacob Carlborg wrote: On 25/07/14 10:55, Walter Bright wrote: Then we'll just get another bug report from AAs behaving differently from ==. No, not as long as it's not used. Well, that's a forlorn hope :-)

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jonathan M Davis via Digitalmars-d
On Friday, 25 July 2014 at 08:21:26 UTC, Jacob Carlborg wrote: By defining opEquals to be opCmp == 0 we're: 1. We're not breaking code where it wasn't broken previously 2. We're fixing broken code. That is when opEqual and opCmp == 0 gave different results Code that worked perfectly fine

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jonathan M Davis via Digitalmars-d
On Friday, 25 July 2014 at 09:12:11 UTC, Jacob Carlborg wrote: On 25/07/14 10:48, Walter Bright wrote: Putting it simply, 1. == uses opEquals. If you don't supply opEquals, the compiler will make one for you. 2. AAs use ==. See rule 1. Easy to understand, easy to explain, easy to

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jonathan M Davis via Digitalmars-d
On Friday, 25 July 2014 at 08:02:18 UTC, Jacob Carlborg wrote: 1. If neither opCmp or opEquals are defined, the compiler will automatically generate these and will be used for comparison and equivalent 2. If opEquals is defined, lhs == rhs will be lowered to lhs.opEquals(rhs) 3. If opCmp

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Daniel Gibson via Digitalmars-d
Am 25.07.2014 12:07, schrieb Jonathan M Davis: And once you define opEquals, you have to define toHash. So, what you're suggesting would force a lot more code to define toHash, which will likely cause far more bugs than simply requiring that Is it actually hard to define toHash, or should it

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jonathan M Davis via Digitalmars-d
On Friday, 25 July 2014 at 10:27:27 UTC, Daniel Gibson wrote: Am 25.07.2014 12:07, schrieb Jonathan M Davis: And once you define opEquals, you have to define toHash. So, what you're suggesting would force a lot more code to define toHash, which will likely cause far more bugs than simply

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Regan Heath via Digitalmars-d
On Fri, 25 Jul 2014 09:39:11 +0100, Walter Bright newshou...@digitalmars.com wrote: On 7/25/2014 1:02 AM, Jacob Carlborg wrote: 3. If opCmp is defined but no opEquals, lhs == rhs will be lowered to lhs.opCmp(rhs) == 0 This is the sticking point. opCmp and opEquals are separate on purpose,

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jacob Carlborg via Digitalmars-d
On 25/07/14 12:07, Jonathan M Davis wrote: The compiler _never_ defines opCmp for you. You have to do that yourself. So, what you're suggesting would force people to define opEquals just because they defined opCmp unless they wanted to take a performance hit. And once you define opEquals, you

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jacob Carlborg via Digitalmars-d
On 25/07/14 11:46, Jonathan M Davis wrote: Code that worked perfectly fine before is now slower, because it's using opCmp for opEquals when it wasn't before. Who says opCmp need to be slower than opEquals. Even worse, if you define opEquals, you're then forced to define toHash, which is

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Manu via Digitalmars-d
On 25 July 2014 16:50, Walter Bright via Digitalmars-d digitalmars-d@puremagic.com wrote: On 7/24/2014 10:52 PM, Manu via Digitalmars-d wrote: I don't really see how opCmp == 0 could be unreliable or unintended. It was deliberately written by the author, so definitely not unintended, and I

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jacob Carlborg via Digitalmars-d
On 25/07/14 12:09, Jonathan M Davis wrote: The _only_ code that would break would be code that's _already_ broken - code that defines opCmp in a way that's inconsistent with the default opEquals and then doesn't define opEquals. I see no reason to worry about making sure that we don't break

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jacob Carlborg via Digitalmars-d
On 25/07/14 11:37, Walter Bright wrote: We went through the likely code breakage from this in this thread, and it's hard to see any non-broken code breaking. It will also fix regression https://issues.dlang.org/show_bug.cgi?id=13179 and stop that breakage. So opEquals will not be required to

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Ary Borenszweig via Digitalmars-d
On 7/25/14, 3:31 AM, Jonathan M Davis wrote: On Friday, 25 July 2014 at 04:50:38 UTC, Walter Bright wrote: On 7/23/2014 9:45 AM, H. S. Teoh via Digitalmars-d wrote: https://issues.dlang.org/show_bug.cgi?id=13179 Consider also:

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread H. S. Teoh via Digitalmars-d
On Fri, Jul 25, 2014 at 09:46:55AM +, Jonathan M Davis via Digitalmars-d wrote: On Friday, 25 July 2014 at 08:21:26 UTC, Jacob Carlborg wrote: By defining opEquals to be opCmp == 0 we're: 1. We're not breaking code where it wasn't broken previously 2. We're fixing broken code. That is

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread H. S. Teoh via Digitalmars-d
On Fri, Jul 25, 2014 at 12:10:31PM +0100, Regan Heath via Digitalmars-d wrote: On Fri, 25 Jul 2014 09:39:11 +0100, Walter Bright newshou...@digitalmars.com wrote: On 7/25/2014 1:02 AM, Jacob Carlborg wrote: 3. If opCmp is defined but no opEquals, lhs == rhs will be lowered to lhs.opCmp(rhs)

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread H. S. Teoh via Digitalmars-d
On Fri, Jul 25, 2014 at 02:08:55PM +0200, Jacob Carlborg via Digitalmars-d wrote: On 25/07/14 12:09, Jonathan M Davis wrote: The _only_ code that would break would be code that's _already_ broken - code that defines opCmp in a way that's inconsistent with the default opEquals and then

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread H. S. Teoh via Digitalmars-d
On Fri, Jul 25, 2014 at 02:37:46AM -0700, Walter Bright via Digitalmars-d wrote: On 7/25/2014 2:12 AM, Jacob Carlborg wrote: On 25/07/14 10:48, Walter Bright wrote: Putting it simply, 1. == uses opEquals. If you don't supply opEquals, the compiler will make one for you. 2. AAs use ==.

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Tobias Pankrath via Digitalmars-d
On Friday, 25 July 2014 at 13:44:54 UTC, H. S. Teoh via Digitalmars-d wrote: On Fri, Jul 25, 2014 at 12:10:31PM +0100, Regan Heath via Digitalmars-d wrote: On Fri, 25 Jul 2014 09:39:11 +0100, Walter Bright newshou...@digitalmars.com wrote: On 7/25/2014 1:02 AM, Jacob Carlborg wrote: 3. If

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Tobias Pankrath via Digitalmars-d
And it's not like we're making it impossible in the minority case -- if you want a non-linear partial ordering, wouldn't you make sure to define both opCmp and opEquals so that they do the right thing? Since it's an uncommon use case, people would tend to be more careful when implementing it.

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread via Digitalmars-d
On Friday, 25 July 2014 at 14:10:11 UTC, H. S. Teoh via Digitalmars-d wrote: The whole reason the opCmp()==0 thing was brought up, was to eliminate this frustration -- give users a nice way to transition into the correct AA design of using opEquals for their keys, instead of just outright

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread via Digitalmars-d
On Thursday, 24 July 2014 at 08:18:22 UTC, Daniel Gibson wrote: When I implement the comparison operator for my type, I expect it to be used for comparisons - and that includes equality. If I had the feeling that I could implement == in a more efficient way, or that I actually want equality to

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jonathan M Davis via Digitalmars-d
On Friday, 25 July 2014 at 13:34:55 UTC, H. S. Teoh via Digitalmars-d wrote: On Fri, Jul 25, 2014 at 09:46:55AM +, Jonathan M Davis via Digitalmars-d wrote: Even worse, if you define opEquals, you're then forced to define toHash, which is much harder to get right. If you're redefining

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Daniel Gibson via Digitalmars-d
Am 25.07.2014 18:11, schrieb Marc Schütz schue...@gmx.net: I'm astonished that it doesn't work like that already. When I first read the operator overloading docs, I really liked that in D I don't need to define all the individual comparison operators, but only opCmp. I Well, to be fair the

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Daniel Gibson via Digitalmars-d
Am 25.07.2014 20:45, schrieb Jonathan M Davis: On Friday, 25 July 2014 at 13:34:55 UTC, H. S. Teoh via Digitalmars-d wrote: On Fri, Jul 25, 2014 at 09:46:55AM +, Jonathan M Davis via Digitalmars-d wrote: Even worse, if you define opEquals, you're then forced to define toHash, which is much

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jonathan M Davis via Digitalmars-d
On Friday, 25 July 2014 at 12:08:55 UTC, Jacob Carlborg wrote: On 25/07/14 12:09, Jonathan M Davis wrote: The _only_ code that would break would be code that's _already_ broken - code that defines opCmp in a way that's inconsistent with the default opEquals and then doesn't define opEquals. I

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jonathan M Davis via Digitalmars-d
On Friday, 25 July 2014 at 18:54:07 UTC, Daniel Gibson wrote: Am 25.07.2014 20:45, schrieb Jonathan M Davis: On Friday, 25 July 2014 at 13:34:55 UTC, H. S. Teoh via Digitalmars-d wrote: On Fri, Jul 25, 2014 at 09:46:55AM +, Jonathan M Davis via Digitalmars-d wrote: Even worse, if you

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread via Digitalmars-d
On Friday, 25 July 2014 at 18:45:30 UTC, Jonathan M Davis wrote: On Friday, 25 July 2014 at 13:34:55 UTC, H. S. Teoh via Digitalmars-d wrote: On Fri, Jul 25, 2014 at 09:46:55AM +, Jonathan M Davis via Digitalmars-d wrote: Even worse, if you define opEquals, you're then forced to define

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread via Digitalmars-d
On Friday, 25 July 2014 at 18:54:15 UTC, Daniel Gibson wrote: Am 25.07.2014 18:11, schrieb Marc Schütz schue...@gmx.net: I'm astonished that it doesn't work like that already. When I first read the operator overloading docs, I really liked that in D I don't need to define all the individual

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread via Digitalmars-d
On Friday, 25 July 2014 at 13:44:54 UTC, H. S. Teoh via Digitalmars-d wrote: Exactly!! I don't understand why people keep bringing up non-linear partial orderings -- those only apply in a *minority* of cases! Well, if , = etc are only to be used where you have a natural total order then I

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jacob Carlborg via Digitalmars-d
On 2014-07-25 15:51, H. S. Teoh via Digitalmars-d wrote: AA's don't care about keys being orderable, all they care about is that keys should have a hash value, and be comparable. It was a mistake to use opCmp for AA keys in the first place. We're now fixing this mistake. I'm responding to

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jacob Carlborg via Digitalmars-d
On 2014-07-25 20:56, Jonathan M Davis wrote: opEquals will now be used for AA keys, not opCmp. Well, yes. But that was not the case when the code was written. In that case it was to correct to defined opCmp. That's why git master generates errors when you have a struct which defines opCmp

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread H. S. Teoh via Digitalmars-d
On Fri, Jul 25, 2014 at 07:21:04PM +, via Digitalmars-d wrote: On Friday, 25 July 2014 at 13:44:54 UTC, H. S. Teoh via Digitalmars-d wrote: Exactly!! I don't understand why people keep bringing up non-linear partial orderings -- those only apply in a *minority* of cases! Well, if , = etc

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jonathan M Davis via Digitalmars-d
On Friday, 25 July 2014 at 19:03:16 UTC, Marc Schütz wrote: On Friday, 25 July 2014 at 18:45:30 UTC, Jonathan M Davis wrote: And remember that a lot of types have opCmp just to work with AAs, so all of a sudden, _every_ user-defined type which is used as an AA key will have to define toHash.

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Walter Bright via Digitalmars-d
On 7/25/2014 5:10 AM, Jacob Carlborg wrote: On 25/07/14 11:37, Walter Bright wrote: We went through the likely code breakage from this in this thread, and it's hard to see any non-broken code breaking. It will also fix regression https://issues.dlang.org/show_bug.cgi?id=13179 and stop that

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Walter Bright via Digitalmars-d
On 7/25/2014 7:08 AM, H. S. Teoh via Digitalmars-d wrote: You're missing the fact that: 1) Before we fixed the use of typeinfo.compare in aaA.d, users were *required* to define opCmp in order for their types to be usable as AA keys -- because that's what aaA.d used to compare keys. This applies

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Jonathan M Davis via Digitalmars-d
On Friday, 25 July 2014 at 20:07:08 UTC, Jacob Carlborg wrote: On 2014-07-25 20:56, Jonathan M Davis wrote: opEquals will now be used for AA keys, not opCmp. Well, yes. But that was not the case when the code was written. In that case it was to correct to defined opCmp. Yes, but opCmp

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Walter Bright via Digitalmars-d
On 7/25/2014 5:08 AM, Jacob Carlborg wrote: I see no reason why I should define opEquals when opCmp was used for AA keys. You keep ignoring that argument. Allow me to repeat: The thing is, either this suffers from == behaving differently than AAs, or you've made opEquals superfluous by

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Walter Bright via Digitalmars-d
On 7/25/2014 5:10 AM, Ary Borenszweig wrote: Not at all. If you have a type that has partial ordering (only cares about opCmp, not about opEquals), but still keeps the default opEquals, then this would silently break someone's code by changing their opEquals semantic. THIS is the breaking

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread Walter Bright via Digitalmars-d
On 7/25/2014 4:10 AM, Regan Heath wrote: Sure, Andrei makes a valid point .. for a minority of cases. The majority case will be that opEquals and opCmp==0 will agree. In those minority cases where they are intended to disagree the user will have intentionally defined both, to be different. I

Re: WAT: opCmp and opEquals woes

2014-07-25 Thread via Digitalmars-d
On Friday, 25 July 2014 at 20:13:57 UTC, H. S. Teoh via Digitalmars-d wrote: Nobody said anything about making it *impossible* to define non-linear orderings. But opCmp() already make it impossible to define some binary relations that are order-like for , = etc. You cannot return both -1 and

  1   2   >