Pow Expressions - not worth the juice?
user1234
user1234 at 12.de
Tue Feb 3 15:23:09 UTC 2026
On Tuesday, 3 February 2026 at 15:11:17 UTC, jmh530 wrote:
> I have found that R’s custom infix operators are nice [1]. They
> have a good balance between allowing library writers to be
> expressible, as well as a bit of a warning that "here be
> dragons".
>
> For those not familiar, putting an R example into a D context
> it would mean you could do something like
>
> ```
> struct Foo
> double x;
> bool opBinary(string op)(double y)
> if (op == "%divisible%")
> {
> return x % y == 0 ? true : false;
> }
> }
> ```
> where the basically the `"op"` can be anything so long as it is
> delimited in a form like "%op%"
>
> It would be even better if you could do something like (to my
> knowledge `opBinary` would need to be a member function).
>
> ```
> bool opBinary(string op)(double x, double y)
> if (op == "%divisible%")
> {
> return x % y == 0 ? true : false;
> }
> ```
>
> [1] https://www.datamentor.io/r-programming/infix-operator
So you just avoid the call-expression syntax so that you can put
spaces between the operands and the operator ? I'm not sure this
solves any problem. Maybe you can provide enlightning examples ?
The one from your link is not convincing.
More information about the Digitalmars-d
mailing list