Skip to content
Permalink
Browse files

LOGIC-98: fix for LOGIC-98, by making nominal aware of fd.

  • Loading branch information...
namin authored and swannodette committed Jan 11, 2013
1 parent 7e8aa22 commit ef27fa3ed2381f3ad4685d4bc59a298646a4febb
@@ -233,6 +233,7 @@
clojure.lang.IFn
(invoke [c a]
(bind* a
(remcg c)
(fn [a]
(let [t1 (walk a v1)
t2 (walk a v2)]
@@ -241,13 +242,18 @@
(-do-suspc t1 t2 swap a)
(not (lvar? t2))
(-do-suspc t2 t1 swap a)
(= t1 t2)
(loop [a* swap
a a]
(if (empty? a*) a
(recur (rest a*) (bind a (hash (first a*) t2)))))
:else
(do (assert (= t1 t2))
(loop [a* swap
a a]
(if (empty? a*) a
(recur (rest a*) (bind a (hash (first a*) t2)))))))))
(remcg c)))
(let [d1 (get-dom-fd a t1)
d2 (get-dom-fd a t2)]
(bind* a
(if (nil? d2) identity (domfd t1 d2))
(if (nil? d1) identity (domfd t2 d1))
(addcg c))))))))
clojure.core.logic.IConstraintId
(id [this] _id)
clojure.core.logic.IWithConstraintId
@@ -271,9 +277,10 @@
(runnable? [_ a]
(let [t1 (walk a v1)
t2 (walk a v2)]
(or (not (lvar? t1)) (not (lvar? t2)) (= t1 t2))))
(or (not (lvar? t1)) (not (lvar? t2)) (= t1 t2)
(not= (get-dom-fd a t1) (get-dom-fd a t2)))))
clojure.core.logic.IConstraintWatchedStores
(watched-stores [this] #{::clojure.core.logic/subst}))))
(watched-stores [this] #{::clojure.core.logic/subst ::clojure.core.logic/fd}))))

(defn suspc [v1 v2 swap]
(cgoal (-suspc v1 v2 swap)))
@@ -404,6 +404,28 @@
(== [x y] q))))
())))

(deftest test-98-entanglement
(is (= (run* [q]
(nom/fresh [a b c]
(fresh [x y]
(== (nom/tie b (nom/tie a x)) (nom/tie c q))
(infd x (interval 1 3)))))
[(nom/tie 'a_0 1) (nom/tie 'a_0 2) (nom/tie 'a_0 3)]))
(is (= (run* [q]
(nom/fresh [a b c]
(fresh [x y]
(infd y (interval 1 3))
(== (nom/tie b (nom/tie a x)) (nom/tie c q))
(== x y))))
[(nom/tie 'a_0 1) (nom/tie 'a_0 2) (nom/tie 'a_0 3)]))
(is (= (run* [q]
(nom/fresh [a b c d]
(fresh [x y z]
(== (nom/tie b (nom/tie a x)) (nom/tie c z))
(infd x (interval 1 3))
(== (nom/tie d q) z))))
'(1 2 3))))

(deftest test-101-variable-nom-in-hash
(is (= (run* [q]
(nom/fresh [x]

0 comments on commit ef27fa3

Please sign in to comment.
You can’t perform that action at this time.