Exponentiation operator precedence
Mark S. Miller
erights at google.com
Thu Sep 24 18:16:03 UTC 2015
On Thu, Sep 24, 2015 at 11:08 AM, Claude Pache <claude.pache at gmail.com>
wrote:
>
> Le 24 sept. 2015 à 16:11, Brendan Eich <brendan at mozilla.org> a écrit :
>
> And indeed apart from dot (a special form whose right operand must be a
> lexical identifier-name) and square brackets (which isn't an infix operator
> per se), unary operators bind tighter than binary in JS as in C and other
> C-derived languages.
>
>
> 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
>
Before Jason pointed out the discrepancy:
* all of us on the committee who were engaged with the proposal
* including myself,
* all those who reviewed the proposal,
* and all those who implemented the proposal
had the opposite naive expectation. That's the point. In the absence of
learning about this case specifically, many people will be unpleasantly
surprised by #2, and many by #3. Therefore #4 wins. (Actually, it just won
;).)
> multiplication operator in expressions like `-2*x` (although it does not
> matter in that case).
>
>
> without having to parenthesize unduly, but one cannot write
>
> let z = -x ** y;
>
> The user is forced by an early error to write either (-x)**y or -(x**y).
>
>
> In traditional math notation, when you mean `(-x)**n`, you write (-x)ⁿ
> with mandatory parentheses, so I don’t expect that many people will be
> tempted to miswrite it `-x ** n`.
>
> 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
> ```
>
> —Claude
>
>
>
--
Cheers,
--MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150924/588d0e17/attachment.html>
More information about the es-discuss
mailing list