You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stack.elv 399B

123456789101112131415161718192021
  1. fn calc [@a]{
  2. s = []
  3. for x $a {
  4. if (eq $x '+') {
  5. s = [(+ $@s)]
  6. } elif (or (eq $x '*') (eq $x 'x')) {
  7. s = [(* $@s)]
  8. } elif (eq $x '-') {
  9. i = (- $s[-2] $s[-1])
  10. s = [(put $@s | take (- (count $s) 2)) $i]
  11. } elif (eq $x '/') {
  12. i = (/ $s[-2] $s[-1])
  13. s = [(put $@s | take (- (count $s) 2)) $i]
  14. } else {
  15. s = [$@s $x]
  16. }
  17. }
  18. put $@s
  19. }