2 ms·
It's interesting to think that the whole notion of associativity and order of operations only exists because for some reason humans seem to find infix notation
by baddox 15y ago
It's interesting to think that the whole notion of associativity and order of operations only exists because for some reason humans seem to find infix notation more "natural" for binary (or fixed arity) operators than more easily parseable and less ambiguous alternatives like prefix.
- sesqu 15y ago^ ^ 2 3 4 Prefix notation doesn't automatically solve the problem, you need to assume an evaluation order. More specifically, you need to not assume associativity.
- baddox 15y agoIsn't the lack of associativity explicit in prefix notation? Prefix notation doesn't even contain the notion of order of operations. You would convert the infix "2^3^4" to prefix in different ways depending on the associativity of exponentiation: For left associativity (uncommon): ^ ^ 2 3 4 For right associativity (common): ^ 2 ^ 3 4 Of course, all this is assuming all operators are fixed arity, otherwise you need parentheses no matter what.