3 ms·
Simple calculators are actually a bit like functional pipes. There's no precedence. Everything is left or right. Every button is a prefix command: OP ARG or el
by kazinator 2y ago
Simple calculators are actually a bit like functional pipes.
There's no precedence. Everything is left or right. Every button is a prefix command: OP ARG or else just OP.
For instance 3 + 4 x 3 - 1 x 9 - can be evaluated in a particular Lisp dialect as
(lflow 3 (+ 4) (* 3) (- 1) (* 9) -)
Where lflow is a left inserting pipe operator. It begins with the value 3, inserts it as the left argument into (+ 4) to actively produce (+ 3 4) and so on.
In the calculator, the result of the previous operation is similarly another argument to OP, which is inserted on the left. It can be understood as being held in an accumulator register.
If OP requires ARG, the evaluation doesn't occur until another OP is entered, or else the = button, which roughly means end of ARG. But OPs that take no argument other than the accumulator dispatch immediately. When OP ARG is followed by multiple =, it is repeated that many times.
When an ARG is entered not preceded by an OP, it replaces the accumulator.
In some calculators, when a new ARG value is entered this way, followed by =, the value is somehow substituted to the previous operation and it is reevaluated, instead of just becoming the new accumulator.