Walter Bright wrote:
Andrei Alexandrescu wrote:
In order for everyone to air an informed opinion, a related question
is: will loop fusion be allowed with function calls?
Loop fusion currently only works with operators, and adding ^^ would
allow:
a[] = b[] ^^ 3;
But with pow you can't do that:
a[] = pow(b[], 3);
Andrei
P.S. FWIW, I'm ambivalent on the issue; if functions were allowed for
automatic loop fusion that would tilt my opinion in disfavor of ^^,
and if not, it would tilt my opinion in favor of ^^.
I don't think this is a valid argument for making pow() an operator,
because what about sin()? cos()? It's all the same issue, and they all
can't be operators.
Exponentiation, like addition, multiplication etc.. can be used multiple
times in an expression at the same scope:
a + b + c
a * b * c
a ^^ b ^^ c
xor, sin, cos are only binary & unary operations. I think that is a good
enough argument for which deserves operator over long function name but
unlike the others, exponentiation is right associative so this should
mean the same as:
a ^^ (b ^^ c)
This may also reduce the likely hood of bugs due to mathematical
formulas being expressed incorrectly. It is far too easy to accidentally
write:
a ^^ b ^^ c
as
pow(pow(a,b),c)
This one operator would really help D be accepted into the mathematical
world.