Created
January 22, 2017 15:20
-
-
Save deque-blog/960eef255f9e73eb9527fd6f1ce0925f 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
(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)] | |
(cond | |
(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