Skip to content

Instantly share code, notes, and snippets.

@tmountain
Created March 17, 2017 18:31
Show Gist options
  • Save tmountain/f388558ff47916d841312e22576be713 to your computer and use it in GitHub Desktop.
Save tmountain/f388558ff47916d841312e22576be713 to your computer and use it in GitHub Desktop.
(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