Permalink
Browse files

LOGIC-69: All IWalkTerm implementations should recurse.

  • Loading branch information...
lynaghk authored and David Nolen committed Nov 21, 2012
1 parent 7f95eb0 commit bd65104ec3fda79790655d4be8a9be436f2c0d54
Showing with 27 additions and 4 deletions.
  1. +6 −4 src/main/clojure/clojure/core/logic.clj
  2. +21 −0 src/test/clojure/clojure/core/logic/tests.clj
@@ -1537,7 +1537,8 @@
(loop [v v r (-uninitialized v)]
(if (seq v)
(let [[vfk vfv] (first v)]
- (recur (next v) (assoc r vfk (f vfv))))
+ (recur (next v) (assoc r (walk-term (f vfk) f)
+ (walk-term (f vfv) f))))
r))
(meta v)))
@@ -1551,15 +1552,15 @@
clojure.lang.ISeq
(walk-term [v f]
(with-meta
- (map f v)
+ (map #(walk-term (f %) f) v)
(meta v)))
clojure.lang.IPersistentVector
(walk-term [v f]
(with-meta
(loop [v v r (transient [])]
(if (seq v)
- (recur (next v) (conj! r (f (first v))))
+ (recur (next v) (conj! r (walk-term (f (first v)) f)))
(persistent! r)))
(meta v)))
@@ -1573,7 +1574,8 @@
(loop [v v r (transient {})]
(if (seq v)
(let [[vfk vfv] (first v)]
- (recur (next v) (assoc! r vfk (f vfv))))
+ (recur (next v) (assoc! r (walk-term (f vfk) f)
+ (walk-term (f vfv) f))))
(persistent! r)))
(meta v))))
@@ -1081,6 +1081,27 @@
(is (= (unifier '(?x 2 . ?y) '(1 9 3 4 5))
nil)))
+(deftest test-unifier-7
+ (is (= (unifier '(?x 2 . ?y) '(1 9 3 4 5))
+ nil)))
+
+(deftest test-unifier-8 ;;nested maps
+ (is (= (unifier '{:a {:b ?b}} {:a {:b 1}})
+ {:a {:b 1}})))
+
+(deftest test-unifier-9 ;;nested vectors
+ (is (= (unifier '[?a [?b ?c] :d] [:a [:b :c] :d])
+ [:a [:b :c] :d])))
+
+(deftest test-unifier-10 ;;nested seqs
+ (is (= (unifier '(?a (?b ?c) :d) '(:a (:b :c) :d))
+ '(:a (:b :c) :d))))
+
+(deftest test-unifier-11 ;;all together now
+ (is (= (unifier '{:a [?b (?c [?d {:e ?e}])]} {:a [:b '(:c [:d {:e :e}])]})
+ {:a [:b '(:c [:d {:e :e}])]})))
+
+
(deftest test-binding-map-1
(is (= (binding-map '(?x ?y) '(1 2))
'{?x 1 ?y 2})))

0 comments on commit bd65104

Please sign in to comment.