Skip to content

Instantly share code, notes, and snippets.

@gfredericks
Created December 19, 2012 04:00
Show Gist options
  • Save gfredericks/4334295 to your computer and use it in GitHub Desktop.
Save gfredericks/4334295 to your computer and use it in GitHub Desktop.
(defn condr*
[& goals]
(if (= 1 (count goals))
(first goals)
(let [goals (shuffle goals)]
(conde
[(first goals)]
[(apply condr* (rest goals))]))))
(defmacro condr
"Same as conde but clauses are scrambled on each call."
[& clauses]
`(condr* ~@(for [clause clauses] (cons `all clause))))
;; example usage
(defn listso
[x]
(condr
[(membero x [:a :b :c])]
[(== [] x)]
[(fresh [a b] (listso a) (listso b) (== [a b] x))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment