Overloading relational operators separately; thoughts?

Minty Fresh via Digitalmars-d digitalmars-d at puremagic.com
Sun Oct 2 08:51:32 PDT 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.


More information about the Digitalmars-d mailing list