templating opEquals/opCmp (e.g. for DSL/expression templates)

Nicholas Wilson iamthewilsonator at hotmail.com
Tue Feb 12 13:22:12 UTC 2019


On Tuesday, 12 February 2019 at 12:35:50 UTC, Jonathan M Davis 
wrote:
> On Tuesday, February 12, 2019 4:35:28 AM MST Nicholas Wilson
>> Link?
>
> He's said as much on several occasions over the years, but 
> here's a link to one such comment:
>
> https://forum.dlang.org/post/nsffdd$1h6m$1@digitalmars.com

Thanks

> The limitations are deliberate based on the idea that 
> comparison operators need to be consistent and predictable, and 
> should have a close relationship to the mathematical meaning of 
> the operators. Overloading <= to mean something other than 
> "less than or equal" is considered poor style in D, and the 
> same goes for the other arithmetic operators.

I don't think that sentiment changes under the use of <= for 
symbolic less-than as opposed to logical less-than.

> The use of them to create DSLs (a technique called "expression 
> templates"
> in C++) is discouraged in D, for several reasons. The 
> recommended way to create DSLs in D is to parse strings using 
> CTFE. An excellent example of that is the std.regex package.

Regex fundamentally deals with strings so is a poor choice for 
comparison (i.e. strings is the right way to do it for regexen, 
but not for everything). My use case is "give me a form of code 
that is symbolically the same that I can execute later".

> There are no plans to change this.

Oh well, more things to discuss at dconf. That whole thread seems 
to be Walter either being stubborn or not getting it (or both).


More information about the Digitalmars-d mailing list