Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(defn- make-op
[rator rands]
(if (< 1 (count rands))
(into [rator] rands)
(first rands)))
(defn- optimize-op
[[rator & rands] binary-op neutral]
(let [{csts true vars false} (group-by cst? rands)
sum-cst (reduce binary-op neutral csts)]
(empty? vars) (cst sum-cst)
(= neutral sum-cst) (make-op rator vars)
:else (make-op rator (into [(cst sum-cst)] vars))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment