Created
May 17, 2011 19:39
-
-
Save jasonjckn/977216 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns calc (:gen-class)) | |
| (defmulti calc (fn [t] (if (seq? t) (first t) :num))) | |
| (defn def-prefix-op [sym f] | |
| (defmethod calc sym [[op & args]] (apply f (map calc args)))) | |
| (doseq [[sym op] [['+ +] ['- -] | |
| ['* *] ['/ /] | |
| ['sin #(Math/sin %)]]] | |
| (def-prefix-op sym op)) | |
| (defmethod calc :num [n] n) | |
| (defn -main [] | |
| (letfn [(prompt [] (print "=>") (flush) (read-line))] | |
| (println (calc (read-string (prompt))))) | |
| (recur)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment