Exponentiation operator precedence

Brendan Eich brendan at mozilla.org
Wed Aug 26 17:28:55 UTC 2015


Yehuda Katz cited an acronym taught when he was a wee lad learning 
algebra: PEMDAS (Parentheses, Exponentiation, Multiplication/Dviistion, 
Addition/Subtraction). Who else learned this?

There's nothing sacrosanct about binary precedence being generally lower 
than unary. Consider the property access operators in JS. But the 
precedent to which all cited languages bow is Math and that's what 
programmers (mostly) study. I think you are making too much out of the 
local -x ** y case in light of this global argument.

/be

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).
>


More information about the es-discuss mailing list