Exponentiation operator precedence

Herby Vojčík herby at mailbox.sk
Fri Sep 25 11:09:58 UTC 2015



Claude Pache wrote:
>
> I just wonder why it is important that unary binds tighter? For
> instance, before I carefully studied the issue of this thread, I have
> never expected that unary minus binds tighter than binary multiplication
> operator in expressions like `-2*x` (although it does not matter in that
> case).
>
> Making the parentheses mandatory here will be somewhat annoying in
> perfectly reasonable expressions, where you usually don’t use
> parentheses in real math notation., like:
> ```
> let s2 = - x**2 - y**2 - z**2 + t**2
> ```

I would overcome it and do not write the parens:

   let s2 = 0 - x**2 - y**2 - z**2 + t**2

Writing mandatory parens here is ugly.

In fact, I am surprised "-2" is unary minus with 2, I thought it is 
number -2. And similarly to Claude, I always read -x*y in math notation, 
that is, as -(x*y). Luckily, for multiplication it does not matter.

Herby


More information about the es-discuss mailing list