Skip to content

Instantly share code, notes, and snippets.

@benfleis

benfleis/foo.clj Secret

Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benfleis/ddf17381dcd7dd112236 to your computer and use it in GitHub Desktop.
Save benfleis/ddf17381dcd7dd112236 to your computer and use it in GitHub Desktop.
(defn explode-conjuncts [conjuncts]
"create sequence of [conjunct term] for all terms in all conjuncts"
(for [conjunct conjuncts
term (remove #{'not 'and} (flatten conjunct))]
[conjunct term]))
(defn make-conjunct-terms-map [conjuncts]
"build map of <conjunct> -> #{terms}"
(->> conjuncts
(explode-conjuncts)
(group-by first) ; group by conjunct
(map second)
(map (fn [ct-seq] [(ffirst ct-seq) (set (map second ct-seq))]))
(into {})))
(def conjuncts
['[and f1 f2 f3]
'[and f1 f2]
'[not f4]])
(def conjunct->terms (make-conjunct-terms-map conjuncts))
;; > conjunct->terms
;; {[and f1 f2 f3] #{f1 f3 f2}, [and f1 f2] #{f1 f2}, [not f4] #{f4}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment