Exponentiation operator precedence
Waldemar Horwat
waldemar at google.com
Tue Aug 25 01:10:20 UTC 2015
On 08/24/2015 17:24, Jason Orendorff wrote:
> On Mon, Aug 24, 2015 at 5:45 PM, Waldemar Horwat <waldemar at google.com> wrote:
>> Let's not. As I said at the last meeting, making ** bind tighter than unary
>> operators would break x**-2. And making it sometimes tighter and sometimes
>> looser would be too confusing and lead to other opportunities for precedence
>> inversion.
>
> Don't you think having `-x**2` mean the same thing as `x**2` is more
> confusing? It seems like it will cause problems for the exact
> programmers we are trying to help with this feature.
>
> What you're describing as "sometimes tighter and sometimes looser" I
> would call "the same precedence". It's even easier to specify than the
> current proposal:
>
> UnaryExpression : PostfixExpression ** UnaryExpression
>
> An expression using both `**` and unary `-` is then parsed right-associatively:
>
> -a ** -b ** -c ** -d
> means -(a ** (-(b ** (-(c ** (-d))))))
That has different right and left precedence and is probably the closest to the mathematical intent. However, it does carry other surprises. What does each of the following do?
++x ** y;
x++ ** y;
x ** ++y;
x ** y++;
Waldemar
More information about the es-discuss
mailing list