Skip to content

Instantly share code, notes, and snippets.

@gfredericks
Created December 19, 2012 04:00

Revisions

  1. gfredericks created this gist Dec 19, 2012.
    23 changes: 23 additions & 0 deletions condr.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    (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))]))