From ce1e8b7ddc229bfb6d96cd710af54f49e962b6da Mon Sep 17 00:00:00 2001 From: "Kevin J. Lynagh" Date: Tue, 20 Nov 2012 17:49:46 -0800 Subject: [PATCH] LOGIC-69: All IWalkTerm implementations should recurse. --- src/main/clojure/clojure/core/logic.clj | 10 ++++++---- src/test/clojure/clojure/core/logic/tests.clj | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main/clojure/clojure/core/logic.clj b/src/main/clojure/clojure/core/logic.clj index b501c16..b5a0bc6 100644 --- a/src/main/clojure/clojure/core/logic.clj +++ b/src/main/clojure/clojure/core/logic.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,7 +1552,7 @@ clojure.lang.ISeq (walk-term [v f] (with-meta - (map f v) + (map #(walk-term (f %) f) v) (meta v))) clojure.lang.IPersistentVector @@ -1559,7 +1560,7 @@ (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)))) diff --git a/src/test/clojure/clojure/core/logic/tests.clj b/src/test/clojure/clojure/core/logic/tests.clj index 1c1b249..b5c6876 100644 --- a/src/test/clojure/clojure/core/logic/tests.clj +++ b/src/test/clojure/clojure/core/logic/tests.clj @@ -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}))) -- 1.7.10