RosettaCodeData/Task/Parsing-RPN-calculator-algorithm/Quackery/parsing-rpn-calculator-algorithm.quackery
2023-07-01 13:44:08 -04:00

36 lines
1 KiB
Text

[ stack ] is switch.arg ( --> [ )
[ switch.arg put ] is switch ( x --> )
[ switch.arg release ] is otherwise ( --> )
[ switch.arg share
!= iff ]else[ done
otherwise
]'[ do ]done[ ] is case ( x --> )
[ say "Applying: "
swap echo$ sp
temp take
temp take
swap rot do
temp put ] is apply ( $ x --> )
[ say "Pushing: " dup echo$ sp
$->n drop temp put ] is isnumber ( $ --> )
[ temp copy echo cr ] is display ( --> )
[ nest$ witheach
[ dup switch
[ $ '+' case [ ' + apply ]
$ '-' case [ ' - apply ]
$ '*' case [ ' * apply ]
$ '/' case [ ' / apply ]
$ '^' case [ ' ** apply ]
otherwise [ isnumber ] ]
display ]
temp take ] is rpncalc ( $ --> n )
$ "3 4 2 * 1 5 - 2 3 ^ ^ / +" rpncalc
say "Result: " echo