Skip to content

Instantly share code, notes, and snippets.

@robertpfeiffer
Created January 23, 2009 14:45
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 robertpfeiffer/51030 to your computer and use it in GitHub Desktop.
Save robertpfeiffer/51030 to your computer and use it in GitHub Desktop.
(defn cartp
"cartesian product"
([] ())
([coll] (map list coll))
([coll & rest] (for [x coll y (apply cartp rest)] (conj y x))))
(defn closure-under?
[op vals check]
(every? (fn [[a b]] (check (op a b))) (cartp vals vals)))
(defn a-associative?
[op example-vals]
(every? (fn [[a b c]] (= (op a (op b c)) (op (op a b) c)))
(cartp example-vals example-vals example-vals)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment