Exponentiation operator precedence
dehrenberg at chromium.org
Tue Aug 25 00:27:23 UTC 2015
On Mon, Aug 24, 2015 at 3:45 PM, Waldemar Horwat <waldemar at google.com> wrote:
> On 08/24/2015 10:08, Jason Orendorff wrote:
>> In math, -x² is -(x²), not (-x)². But as proposed for JS, -x**2 is
>> PHP, Python, Haskell, and D side with the traditional algebraic
>> notation, against JS. Here's PHP:
>> $ php -r 'print(-2 ** 2);'
>> >>> -2 ** 2
>> Prelude> -2 ^ 2
>> The D grammar: http://dlang.org/grammar.html#UnaryExpression
>> Let's switch.
> 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
Agreed that the precedence should not bind sometimes tighter and
sometimes looser is problematic.
I think following the way other languages solve the same problem is
more important for minimizing user surprise than any particular
expression looking especially good. Looking kinda similar to other
languages in surface syntax has been a major advantage of JS all
More information about the es-discuss