News for hackers. Stuff that matters.
Re:Unix History and the `DC` Calculator by kragen on Monday September 02, 2024 @01:28AM (#41422844)
postfix notation only needs a stack of numbers, it's shallower, and it does one operation per token. zuse's z3 didn't have much memory or complex control logic

when you have said

   * + 3 4 - 5
(assuming dyadic operators) you have a stack containing an operator, a computed result, another operator, and an entered operand. when you complete the expression with

    6
the computation of the result, -1, should trigger the lurking multiplication. the machine's sequencing is state-dependent

by contrast, in

    3 4 + 5 6 - *
there are never more than three things on the stack in this expression, operators are never on the stack, and no input ever triggers more than one operation. from a user interface perspective, the user also gets faster feedback

i just wrote a command-line postfix calculator in c on my cellphone touchscreen in 20 minutes. it's 31 lines of code. i think that to do that so simply with prefix you have to do it right to left, effectively making it postfix

There are no comments on this comment yet.