Here's a handy macro for using core.logic to find an element in a collection that matches a set of rules.
"Convenience macro for finding elements in a
collection that match a set of rules.
Generates a new fresh lvar named ~lvar,
which should be membero coll. Pass additional
rules in body. Unify lvar with something else
so its value can escape the scope of this macro."
[lvar coll & body]
(clojure.core.logic/membero ~lvar ~coll)
You'll want to unify
lvar (which is made fresh) with something else so its value can escape the scope of the macro body.
[el coll out]
(membero-such e coll
(clojure.core.logic/== e el)
(clojure.core.logic/== e out)))
(find-el :b [:a :b :c] q)) ; => (:b)