Created
March 17, 2017 18:31
-
-
Save tmountain/f388558ff47916d841312e22576be713 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
(defrecord Constant [value]) | |
(defrecord BinaryPlus [lhs rhs]) | |
(defmulti evaluate class) | |
(defmethod evaluate Constant | |
[c] (:value c)) | |
(defmethod evaluate BinaryPlus | |
[bp] (+ (evaluate (:lhs bp)) (evaluate (:rhs bp)))) | |
(defmulti stringify class) | |
(defmethod stringify Constant | |
[c] (str (:value c))) | |
(defmethod stringify BinaryPlus | |
[bp] | |
(clojure.string/join " + " [(stringify (:lhs bp)) | |
(stringify (:rhs bp))])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment