October 02, 2016
On Saturday, 1 October 2016 at 17:53:44 UTC, Russel Winder wrote:
> On Sat, 2016-10-01 at 14:55 +0000, Chris Wright via Digitalmars-d wrote:
>
>> Groovy doesn't allow you to overload comparison operators
>> individually,
>> and probably most JVM languages likewise. This is to retain
>> compatibility
>> with Java, which has `.compareTo()` instead of `isLessThan()` etc.
>
> Yes it does.  http://groovy-lang.org/operators.html
>
> There is *also* compareTo.
>
>> Ruby allows you to override individual comparison operators, with a
>> special operator `<=>` for combined comparisons. Nim lets you
>> overload
>> arbitrary operators and create your own; some old discussions
>> suggest
>> that the Comparable type is based on `<` alone.
>
> Groovy also supports the spaceship operator.

`<=>` exists for the general case, which is what `opCmp` covers in D. Overloading each relational operator individually is made possible to address any sort of special cases.
The issue being, in D there is no room for any manner of special case.
October 02, 2016
On Wednesday, 28 September 2016 at 01:18:58 UTC, Minty Fresh wrote:
> Currently, D offers fine grained overloading for most of the unary and arithmetic binary operators, but at some point a decision was made to lump together all of the relational operators (and if necessary, the equality operators) into a single function `opCmp`.
> And while it does add a lot of convenience and consistency to how operators behave, it does also put a lot of limitations on what they can do.
>
> [...]

opCmp was a good idea.

Allowing opBinary to bypass opCmp is also a good idea.

Atila
1 2 3 4 5 6 7 8 9 10
Next ›   Last »