Advertisement
Guest User

Untitled

a guest
Sep 30th, 2011
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; using [matchure "0.10.1"]
  2.  
  3. (use '[matchure])
  4.  
  5. (defn-match rpn'
  6.     ([ [?x ?y & ?z ] "*" ] (cons (* x y ) z))
  7.     ([ [?x ?y & ?z ] "+" ] (cons (+ x y ) z))
  8.     ([ ?x "sum" ] [ (reduce + x) ] )
  9.     ([ ?x ?y ] (cons (read-string y) x) ))
  10.  
  11. (defn calculator'[ input ]
  12.     (first (reduce rpn' [] (re-seq #"\S+" input))))
  13.  
  14. (calculator' " 1 2 10 2 3 + * sum ")
  15.  
  16. ; works like a charm ;-)
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement