top | item 42811270

(no title)

persnickety | 1 year ago

RPN is definitely easier to implement. I helped someone do that as a student project and while it was minimally complex, there were no edge cases with the operators.

You pay for that by having a stack rather than a small fixed number of variables.

discuss

order

enriquto|1 year ago

> You pay for that by having a stack rather than a small fixed number of variables.

you can easily add variables to your rpn calculator. For example ">x" pops the top of the stack into the variable x, and "<x" pushes the value of x to the stack.

You can also interpret parentheses as whitespace to enable users to group parts of the computation (but this may become confusing when they write nonsensical parentheses).

ropejumper|1 year ago

They meant that the implementation of a four-function calculator only needs a few fixed variables rather than a stack.

_moof|1 year ago

My HP RPN calculator only has four positions available in its stack, which I imagine makes the implementation a bit simpler than a stack of arbitrary size.

persnickety|1 year ago

The typical 4-function calculator doesn't even allow multiple subtrees of computation, so I think it works out to having something like 2 entries on the stack.

tgv|1 year ago

Classical 4-func calcs are easier, I think. They don't even need a stack, just a place to store the previous value and the current input.