Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; using [matchure "0.10.1"]
- (use '[matchure])
- (defn-match rpn'
- ([ [?x ?y & ?z ] "*" ] (cons (* x y ) z))
- ([ [?x ?y & ?z ] "+" ] (cons (+ x y ) z))
- ([ ?x "sum" ] [ (reduce + x) ] )
- ([ ?x ?y ] (cons (read-string y) x) ))
- (defn calculator'[ input ]
- (first (reduce rpn' [] (re-seq #"\S+" input))))
- (calculator' " 1 2 10 2 3 + * sum ")
- ; works like a charm ;-)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement