Parsing/RPN calculator algorithm: Difference between revisions

m
adding steps in displaying the result
(adding lambdatalk version)
m (adding steps in displaying the result)
Line 2,785:
<lang Scheme>
{calc 3 4 2 * 1 5 - 2 3 pow pow / +}
->
-> 3.0001220703125
3
4 3
2 4 3
8 3
1 8 3
5 1 8 3
-4 8 3
2 -4 8 3
3 2 -4 8 3
8 -4 8 3
65536 8 3
0.0001220703125 3
-> 3.0001220703125
 
where
Line 2,794 ⟶ 2,807:
{if {empty? :x}
then {car :s}
else {calc.rdisp :s}{cdr :xbr}
{calc.r {cdr :x}
{if {unop? {car :x}}
then {cons {{car :x} {car :s}} {cdr :s}}
Line 2,825 ⟶ 2,839:
}}}
 
and using the list and, empty? and disp functions to create
a list from a string and, test its emptynes and display it.
 
{def list
Line 2,837 ⟶ 2,851:
{lambda {:x}
{W.equal? :x nil}}}
 
{def disp
{lambda {:l}
{if {empty? :l}
then
else {car :l} {disp {cdr :l}}}}}
 
Note that everything is exclusively built on 5 lambdatalk primitives: