Skip to content

Instantly share code, notes, and snippets.

@missingfaktor
Created September 10, 2016 12:22
Show Gist options
  • Select an option

  • Save missingfaktor/c1341c4e2c423c9e3d4a2656c0f83f9e to your computer and use it in GitHub Desktop.

Select an option

Save missingfaktor/c1341c4e2c423c9e3d4a2656c0f83f9e to your computer and use it in GitHub Desktop.
(defn evaluate [exp]
(match exp
(:variant :val [x]) x
(:variant :add [x y]) (+ (evaluate x) (evaluate y))
(:variant :multiply [x y]) (* (evaluate x) (evaluate y))))
(def numeric-expression
[:add [:val 2]
[:multiply [:val 4]
[:val 5]]])
(evaluate numeric-expression)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment