Arc Forumnew | comments | leaders | submitlogin
6 points by soegaard 6128 days ago | link | parent

PLT Scheme:

  (require  (lib "match.ss"))

  (define (rpn xs) (rpn2 (list xs ())))
  (define rpn2
    (match-lambda
      [(() (x))                              x]
      [(()  xs)                              (error "extra stuff on stack")]
      [(('/ . _) (0 . _))                    (error "divisision by zero")]
      [(((and a (? symbol?)) . b) (x y . r)) (rpn2 (list b (cons ((eval a) y x) r)))]
      [((a . b) s)                           (rpn2 (list b (cons a s)))]))

  (rpn '(2 2 + 9 1 - /))
  (rpn '(2 2 + 9 9 - /))