Pow Expressions - not worth the juice?
jmh530
john.michael.hall at gmail.com
Tue Feb 3 15:11:17 UTC 2026
On Tuesday, 3 February 2026 at 01:38:03 UTC, Lance Bachmeier
wrote:
> On Monday, 2 February 2026 at 20:23:01 UTC, Sam Potter wrote:
>> On Monday, 2 February 2026 at 17:43:45 UTC, Walter Bright
>> wrote:
>>> https://dlang.org/spec/expression.html#pow_expressions
>>>
>>> They're a bit of an oddball feature in D, in that it's the
>>> only feature that relies on Phobos for its implementation.
>>>
>>> Time for it to go?
>>
>> Please no.
>>
>> Operator overloading for ^^ is a really nice quality of life
>> improvement for numerical and scientific programming.
>>
>> All five major numerical programming languages support this:
>> MATLAB, Python, Fortran, Julia, and R.
>
> We should have more operators, not fewer.
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
More information about the Digitalmars-d
mailing list