Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.49 KB | None | 0 0
  1. : evaluate (s -- i) ( Parse and evaluate string as RPN command )
  2.     { swap " " explode } array_make
  3.     foreach
  4.         swap pop
  5.         dup "+" strcmp not if pop + else
  6.         dup "-" strcmp not if pop - else
  7.         dup "*" strcmp not if pop * else
  8.         dup "/" strcmp not if pop / else
  9.         atoi then
  10.     repeat
  11. ;
  12. : main
  13.     begin
  14.         me @ "Type a term in reverse polish notation: (x=exit)" notify
  15.         read
  16.         dup "x" strcmp
  17.         dup if
  18.             swap evaluate
  19.             me @ swap intostr notify
  20.         else
  21.             swap pop
  22.         then
  23.     while
  24. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement