Permalink
Browse files

LOGIC-46: Unification on Struct Maps Causes Error

  • Loading branch information...
1 parent 9793085 commit a62e7f11f02ade156043d309dc94166c9ec581b8 David Nolen committed Oct 5, 2012
Showing with 19 additions and 8 deletions.
  1. +4 −8 src/main/clojure/clojure/core/logic.clj
  2. +15 −0 src/test/clojure/clojure/core/logic/tests.clj
@@ -1502,21 +1502,17 @@
clojure.lang.IPersistentMap
(unify-with-map [v u s]
- ;; TODO: the key count of v & u must be the same
- (let [ks (keys u)]
- (loop [ks ks u u v v s s]
+ (when (= (count u) (count v))
+ (loop [ks (keys u) s s]
(if (seq ks)
(let [kf (first ks)
vf (get v kf ::not-found)]
(if (= vf ::not-found)
nil
(if-let [s (unify s (get u kf) vf)]
- ;; TODO: there's no need to dissoc the keys - breaks struct maps
- (recur (next ks) (dissoc u kf) (dissoc v kf) s)
+ (recur (next ks) s)
nil)))
- (if (seq v)
- nil
- s))))))
+ s)))))
;; -----------------------------------------------------------------------------
;; Unify Refinable with X
@@ -352,6 +352,21 @@
m2 {1 4 3 x}]
(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

0 comments on commit a62e7f1

Please sign in to comment.