Skip to content

Instantly share code, notes, and snippets.

@robertpfeiffer
Created February 22, 2009 21:27
Show Gist options
  • Select an option

  • Save robertpfeiffer/68622 to your computer and use it in GitHub Desktop.

Select an option

Save robertpfeiffer/68622 to your computer and use it in GitHub Desktop.
(defmatch s
([[+ M N]] ((:number M) (:number N)) {m 'M n 'N} (+ m n))
([[+ 0 N]] () {n 'N} n)
([[+ N 0]] () {n 'N} n)
([[+ A [+ B C]]] () {a'A,b'B,c'C} ['+ ['+ a b] c])
([[* M N]] ((:number M) (:number N)) {m 'M n 'N} (* m n))
([[* 0 N]] () {n 'N} 0)
([[* N 0]] () {n 'N} 0)
([[* A [* B C]]] () {a'A,b'B,c'C} ['* ['* a b] c])
([A] () {a 'A} a))
(defmatch simplify
([[Op A B]] () {op 'Op a 'A b 'B} (s [op (simplify a) (simplify b)]))
([A] () {a 'A} a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment