4 ms·
Huh? Why does Polish notation require parenthesis but Reverse Polish not? I thought the whole point of Polish notation was that it didn't require parens. Unles
by jkarni 12y ago
Huh? Why does Polish notation require parenthesis but Reverse Polish not? I thought the whole point of Polish notation was that it didn't require parens.
Unless your operators don't have a fixed arity, anyhow (Lisp's don't). But even then I don't see how RPN is in a better position...
- Murk 12y agoI am not sure it does, but: (7 + 2) * (2 + 5) in normal, infix notation * + 7 2 + 2 5 in polish notation, http://en.wikipedia.org/wiki/Polish_notation http://en.wikipedia.org/wiki/Polish_notation vs reverse polish which is: 7 2 + 2 5 + * (or 7 2 25 + + * ) which is easy to evaluate, but not necessarily to read)
- jkarni 12y agoSorry, I should have added some context: >Notice that RPN requires no parenthesis, unlike the polish notation of Lisps where the operator comes first, and RPN requires no precedence rules, unlike the infix notation used in most programming languages and in everyday arithmetic. This seems wrong to me. It's the lack of variadic functions that is the relevant difference to lisp in terms of doing away with parens, not PN vs RPN. Love the article, though
- cicero 12y agoI think RPN was initially adopted for electronic calculators because it is easy to implement. As numbers are entered, they are pushed onto the stack, and then the operations pop operands off of the stack and push results back on the stack. Similarly, code in an RPN language like Forth can be executed left-to-right by pushing the operands onto the stack, and then the operation manipulates the contents of the stack.