Semantics of ^^

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Wed Dec 9 01:19:31 PST 2009


Don wrote:
> Bill Baxter wrote:
>> On Tue, Dec 8, 2009 at 2:32 AM, Don <nospam at nospam.com> wrote:
>>> Based on everyone's comments, this is what I have come up with:
>>>
>>> --------------------
>>> x ^^ y is right associative, and has a precedence intermediate between
>>> multiplication and unary operators.
>>
>> Is that consistent with math?   I think in math they usually write
>> (-1)^n with parens.
>> See for example the sin power series here:
>> http://en.wikipedia.org/wiki/Power_series
>>
>> What's the rationale for going against math here?
> 
> Hmm. Several other languages give it that precedence. But you're right, 
> it should be even higher than unary. Between unary and postfix ?

Good catch, I missed that one in the original proposal. Between unary 
and postfix sounds right. I would be extremely surprised if -2^^2 
evaluated to 4, but I would have to think twice about i++^^2.

-Lars



More information about the Digitalmars-d mailing list