Skip to content

Commit

Permalink
LOGIC-46: Unification on Struct Maps Causes Error
Browse files Browse the repository at this point in the history
  • Loading branch information
David Nolen committed Oct 5, 2012
1 parent 9793085 commit a62e7f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/main/clojure/clojure/core/logic.clj
Expand Up @@ -1502,21 +1502,17 @@


clojure.lang.IPersistentMap clojure.lang.IPersistentMap
(unify-with-map [v u s] (unify-with-map [v u s]
;; TODO: the key count of v & u must be the same (when (= (count u) (count v))
(let [ks (keys u)] (loop [ks (keys u) s s]
(loop [ks ks u u v v s s]
(if (seq ks) (if (seq ks)
(let [kf (first ks) (let [kf (first ks)
vf (get v kf ::not-found)] vf (get v kf ::not-found)]
(if (= vf ::not-found) (if (= vf ::not-found)
nil nil
(if-let [s (unify s (get u kf) vf)] (if-let [s (unify s (get u kf) vf)]
;; TODO: there's no need to dissoc the keys - breaks struct maps (recur (next ks) s)
(recur (next ks) (dissoc u kf) (dissoc v kf) s)
nil))) nil)))
(if (seq v) s)))))
nil
s))))))


;; ----------------------------------------------------------------------------- ;; -----------------------------------------------------------------------------
;; Unify Refinable with X ;; Unify Refinable with X
Expand Down
15 changes: 15 additions & 0 deletions src/test/clojure/clojure/core/logic/tests.clj
Expand Up @@ -352,6 +352,21 @@
m2 {1 4 3 x}] m2 {1 4 3 x}]
(is (= (unify empty-s m1 m2) nil)))) (is (= (unify empty-s m1 m2) nil))))


(defstruct foo-struct :a :b)

(deftest unify-struct-map-1
(let [x (lvar 'x)
m1 (struct-map foo-struct :a 1 :b 2)
m2 (struct-map foo-struct :a 1 :b x)
os (ext-no-check empty-s x 2)]
(is (= (unify empty-s m1 m2) os))))

(deftest unify-struct-map-2
(let [x (lvar 'x)
m1 (struct-map foo-struct :a 1 :b 2)
m2 (struct-map foo-struct :a 1 :b 3)]
(is (= (unify empty-s m1 m2) nil))))

;; ============================================================================= ;; =============================================================================
;; walk ;; walk


Expand Down

0 comments on commit a62e7f1

Please sign in to comment.