Not an fd bug patch, but a disunify lcons bug patch for: https://dev.clojure.org/jira/browse/LOGIC-174
On Monday, October 30, 2017 at 6:49:49 PM UTC-3, David Nolen wrote: > > There are a couple of bugs around clp(fd) I simply haven't had time to > look into and unlikely too anytime soon sadly. You might want to check JIRA > to see what other users have reported - > https://dev.clojure.org/jira/browse/LOGIC > > Patches are welcome of course! > > David > > On Sat, Oct 28, 2017 at 1:31 PM, Pierre Baille <[email protected] > <javascript:>> wrote: > >> Hello Everyone! >> >> I'm starting with core.logic, i'm trying to implement a simple relation >> >> But the results are incomplete. >> >> does anybody can help me to understand what I'm doing wrong here? >> >> assuming core.logic aliased as l, and core.logic.fd :as fd >> >> (defn zip+o [rel l1 l2 l3] >> (conde >> [(== () l1) (== () l2) (== () l3)] >> [(fresh [fl1 rl1 fl2 rl2 fl3 rl3] >> (l/conso fl1 rl1 l1) >> (l/conso fl2 rl2 l2) >> (fd/in fl1 fl2 fl3 (fd/interval 100)) >> (fd/+ fl1 fl2 fl3) >> (zip+o rel rl1 rl2 rl3))])) >> >> (run* [q] >> (fresh [a b] >> (== q [a b]) >> (zip+o a b [2 2]))) >> ;=> >> ([(0 0) (2 2)] >> [(1 0) (1 2)] >> [(2 0) (0 2)]) >> >> but the result should be: >> >> ([(0 0) (2 2)] >> [(1 0) (1 2)] >> [(2 0) (0 2)] >> [(0 1) (2 1)] >> [(0 2) (2 0)] >> [(1 1) (1 1)] >> [(1 2) (1 0)] >> [(2 1) (0 1)] >> [(2 2) (0 0)]) >> >> In the other way it seems to work: >> >> (run* [q] >> (zip+o [1 1] [3 3] q)) >> >> ;=> ((4 4)) >> >> -- >> You received this message because you are subscribed to the Google Groups >> "minikanren" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at https://groups.google.com/group/minikanren. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "minikanren" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/minikanren. For more options, visit https://groups.google.com/d/optout.
>From ea75a27571e9aaeedc6e512f01db443a7e81ddcf Mon Sep 17 00:00:00 2001 From: "[email protected]" <[email protected]> Date: Tue, 12 Dec 2017 20:18:58 -0300 Subject: [PATCH] LOGIC-174: Rewrite disunify lcons --- src/main/clojure/clojure/core/logic.clj | 26 ++++++++++++++------------ src/test/clojure/clojure/core/logic/tests.clj | 12 ++++++++++++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/main/clojure/clojure/core/logic.clj b/src/main/clojure/clojure/core/logic.clj index 040372a..65dd65d 100644 --- a/src/main/clojure/clojure/core/logic.clj +++ b/src/main/clojure/clojure/core/logic.clj @@ -2329,18 +2329,20 @@ nil))) (lcons? v) - (loop [u u v (seq v) cs cs] - (if (lvar? u) - (if (lvar? v) - (disunify s u v cs) - nil) - (cond - (lvar? v) nil - (and (lcons? u) (lcons? v)) - (if-let [cs (disunify s (lfirst u) (lfirst v) cs)] - (recur (lnext u) (lnext v) cs) - nil) - :else nil))) + (loop [u u + v v + cs cs] + (let [uv (lfirst u) + vv (lfirst v) + cs (disunify s uv vv cs)] + (if (nil? cs) + nil + (let [u' (lnext u) + v' (lnext v)] + (if (and (lcons? u') + (lcons? v')) + (recur u' v' cs) + (disunify s u' v' cs)))))) :else nil)) diff --git a/src/test/clojure/clojure/core/logic/tests.clj b/src/test/clojure/clojure/core/logic/tests.clj index 9e70b52..cc9967d 100644 --- a/src/test/clojure/clojure/core/logic/tests.clj +++ b/src/test/clojure/clojure/core/logic/tests.clj @@ -3572,3 +3572,15 @@ (let [result (u/prep '([?x] . ?foo)) [head] (lfirst result)] (is (lvar? head))) ) + + +(deftest test-logic-174-disunify-pair + (is (run 1 [q] + (!= (lcons 1 1) (lcons 1 2))) + '(_0)) + (is (run 1 [q] + (!= (lcons 1 1) (lcons 1 1))) + '()) + (is (run 1 [q] + (!= (lcons 1 1) (lcons 1 q))) + '((_0 :- (!= (_0 1)))))) -- 2.7.4
