3 ms·
> All operators have equal precedence, so parentheses are required when mixing operators. Doesn't that mean it rejects precedence? In a language equal preceden
by masklinn 9y ago
> All operators have equal precedence, so parentheses are required when mixing operators.
Doesn't that mean it rejects precedence? In a language equal precedence (e.g. Smalltalk), operators would just be executed from LTR or RTL.
- evincarofautumn 9y agoI agree, although I suppose different operators could still have different associativity in a language without precedence. I took that phrasing from the “Puffs the Language” documentation.
- masklinn 9y ago> I suppose different operators could still have different associativity in a language without precedence That… is true, and I have a hard time computing how it would even work.
- klodolph 9y agoThink exponentiation, where 2^3^4 might be 2^(3^4), but where subtraction 2-3-4 is (2-3)-4.
- mnarayan01 9y agoConsider: 2-3^4
- irishsultan 9y agoSince there is no precedence in this (hypothetical) language that would be an invalid expression.
- evincarofautumn 9y agoOne way to do it would be to have a default associativity between different operators, but chains of the same operator can override it, e.g. suppose “⧺” means concatenation (rightward), “×” means repetition (leftward), and the default is leftward: [1, 2] ⧺ [3, 4] ⧺ [5, 6] × 2 × 3 (([1, 2] ⧺ ([3, 4] ⧺ [5, 6])) × 2) × 3 [ [ [1…6], [1…6] ], [ [1…6], [1…6] ], [ [1…6], [1…6] ] ] I dunno how good an idea that would be in practice, though.
- nigeltao 9y agoWhat I mean is that you can't write "2 + 3 * 4", not even with implicit LTR, you have to write either "(2 + 3) * 4" or "2 + (3 * 4)". See e.g the "precedence bug" comment I wrote elsewhere on this page.
- masklinn 9y agoMy point is that's not "equal precedence". Smalltalk has equal precedence, "2 + 3 * 4" parses as "(2 + 3) * 4". If you reject the expression entirely you don't have equal precedences, you have unmixable operators or precedences (the latter being if "2 + 3 - 4" is still allowed).
- nigeltao 9y agoOK, I'll change the wording. Thanks.