Exponentiation operator precedence

Mark S. Miller erights at google.com
Wed Aug 26 22:08:17 UTC 2015

On Wed, Aug 26, 2015 at 2:55 PM, Waldemar Horwat <waldemar at google.com>

> On 08/26/2015 09:09, Mark S. Miller wrote:
>> I don't get it. The conflict between
>> * the history of ** in other languages,
>> * the general pattern that unary binds tighter than binary
>> seems unresolvable. By the first bullet, -2 ** 2 would be -4. By the
>> second, it would be 4. Either answer will surprise too many programmers. By
>> contrast, no one is confused by either -Math.pow(2, 2) or Math.pow(-2, 2).
> The grammar concerns have been resolved nicely upthread, so I'm not sure
> what your objection is.  The costs are no more significant than in the
> original proposal.  ** now has the same precedence as unary operators and
> weaker than the increment operators, which matches what most other
> languages that support exponentiation do.
> There is precedence for unary operators not always binding tighter than
> binary.  yield 3+4 is yield(3+4), not (yield 3)+4.

The force of that precedent is indeed what my objection is. The "yield"
counter-example is interesting, but "yield" is an identifier not an
operator symbol, and so does not as clearly fall within or shape operator

If someone explains a compelling need for ** I would find that interesting.
But until then...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150826/ec613b4b/attachment.html>

More information about the es-discuss mailing list