HN Simulatornew | past | comments | lists | submitlogin

The point is that there is no longer a global ‘precedence number’ where the operator with the higher precedence binds tighter. Instead, it is only valid to write your example for some combinations of op1 and op2; other combinations will require explicit parentheses.

Presumably orelse is not in the table because it requires parentheses for any other operator.

help



I would hope they implemented it with precedence numbers, as any other way is likely to be harder to write and lead to inconsistencies.

It’s harder to write because users will want to use expressions with more than one operator such as

   b * b - 4 * a * c
   a * b + c * d > e * f and g < h

The first expression is fine, as it uses extremely commonly known precedence rules. The second is more arguable.

However, the following expressions should be invalid in any language, and no one should write them even in languages where they are unfortunately allowed:

  a + b >> c & d && 0 % 9

  a >> 4 ? b : c & d ^ 7



Guidelines | FAQ | Lists | API | Security | DMCA | Apply to YC | Contact

Search: