Hmm... how about having some sort of macro-ish construct for this?
SML has something similar (although I don't know the itty-bitty details). The idea is that you declare a token as an infix operator and assign it a function.
An example with a minimal pow operator:
int my_pow(int base, int power) { return pow(base,power); } infix "**" * my_pow; // or infix("**", 4 , my_pow); // 4 is how hard it binds in comparison to other operators
My thought is that this code
int foo = 2**3;
is expanded to
int foo = pow(2,3);
or rather the unoptimized case of
int foo = (pow(2,3));
/ Peter Lundqvist (disjunkt)
Previous text:
2003-05-15 19:38: Subject: top level infix operators
Yes. If new operators are added we have to either hardcode their precedence, associativity etc, or introduce language constructs to control that. Personally I don't think it's worth a generic system with all it means in extra syntax to understand and various ambiguities and conflicts to resolve.
It's better to consider adding specific operators, I think. A power operator could be one, if there's sufficient interest. An alternative in that case is to extend the pow function to try lfuns if it's fed objects it doesn't understand. E.g. m_delete and random already have such things.
As for set operations, the existing `|, `&, `- etc are already used for that. Aren't those enough?
/ Martin Stjernholm, Roxen IS