4 ms·
It's simpler to implement RPN than algebraic notation with precedence. The latter requires an operation stack where operations are stacked until they encounter
by rbanffy 6y ago
It's simpler to implement RPN than algebraic notation with precedence. The latter requires an operation stack where operations are stacked until they encounter a lower precedence operator or the user presses =.
The user types less, the computer does a lot less.
I find it fun to think in RPN.
- jeffbee 6y agoYeah, it feels like the whole "why" is that RPN reflects how the machine works, so it's easier to build it that way.
- ajarmst 6y agoWell, it’s easier to build because it has a terse syntax that requires fewer symbols, doesn’t need precedence and associativity rules, and has no ambiguous instructions. It’s easier to use for the same reasons.
- tome 6y ago> has no ambiguous instructions Really? What do you call an operator applied to an empty stack? A sequence of commands that leaves the stack non-empty? I don't see why that's any less ambiguous than mismatched parentheses.
- jeffbee 6y agoWhy would any person or machine care that the stack wasn't empty?
- jonsen 6y agoAnd there is actually no such thing as an empty stack on an RPN calculator. A four register stack, as is common, always holds four numbers.
- jonsen 6y ago> A sequence of commands that leaves the stack non-empty? That’s actually a feature. It’s even fundamental in concatenative programming languages such as FORTH and Factor.
- jonsen 6y ago> What do you call an operator applied to an empty stack? [Pi] for example is an operator which can push the value of Pi onto an empty stack.
- what-do-I-know 6y agoIt may be easier to build, but that difference is quite small and not likely something that would have influenced the design of a scientific calculator. Many people have found RPN to be a superior user interface, and that’s likely the “why”.
- abhinav22 6y agoYep!! I implemented an rpn calculator in Swift and it was a breeze - very easy to do. Here’s the code: https://github.com/ashok-khanna/RPN-31 https://github.com/ashok-khanna/RPN-31 Here’s the link: https://apps.apple.com/ae/app/rpn-30/id1451413517 https://apps.apple.com/ae/app/rpn-30/id1451413517
- hota_mazi 6y agoYes, the user types less but they have to think more. Don't get me wrong, I love RPN and I've had a stream of HP calculators through my college years (synthetic programming on the HP41!), but... they come at a cognitive price. When you see an expression, you have to process the precedence in your mind to find out the most nested expression and start entering from there. Basically, the calculator is cheating by forcing you to do some of its job.
- hpfr 6y agoThat’s the point. This precedence processing should be intuitive if you’ve learned to do calculations by hand, and it helps you understand the expression as you enter it which makes for easier error detection. It’s also nicer for building up an expression on the fly as opposed to the Answer key on standard calculators. If you’re just copying existing expressions, you might as well use one of those OCR calculators.
- hota_mazi 6y agoThe point is not really whether it's intuitive or not (and for very nested expression, it's really not always intuitive to find the most nested one, especially if you have to remember precedence laws). The point is that it takes time. As much of an RPN fan I am, I am not convinced that the time it takes my brain to identify nested expressions is smaller than the time it would take me to just type the expression left to right on a regular calculator.