Created
December 19, 2012 04:00
-
-
Save gfredericks/4334295 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 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