Skip to content

Commit

Permalink
LOGIC-69: All IWalkTerm implementations should recurse.
Browse files Browse the repository at this point in the history
  • Loading branch information
lynaghk authored and David Nolen committed Nov 21, 2012
1 parent 7f95eb0 commit bd65104
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/clojure/clojure/core/logic.clj
Expand Up @@ -1537,7 +1537,8 @@
(loop [v v r (-uninitialized v)] (loop [v v r (-uninitialized v)]
(if (seq v) (if (seq v)
(let [[vfk vfv] (first 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)) r))
(meta v))) (meta v)))


Expand All @@ -1551,15 +1552,15 @@
clojure.lang.ISeq clojure.lang.ISeq
(walk-term [v f] (walk-term [v f]
(with-meta (with-meta
(map f v) (map #(walk-term (f %) f) v)
(meta v))) (meta v)))


clojure.lang.IPersistentVector clojure.lang.IPersistentVector
(walk-term [v f] (walk-term [v f]
(with-meta (with-meta
(loop [v v r (transient [])] (loop [v v r (transient [])]
(if (seq v) (if (seq v)
(recur (next v) (conj! r (f (first v)))) (recur (next v) (conj! r (walk-term (f (first v)) f)))
(persistent! r))) (persistent! r)))
(meta v))) (meta v)))


Expand All @@ -1573,7 +1574,8 @@
(loop [v v r (transient {})] (loop [v v r (transient {})]
(if (seq v) (if (seq v)
(let [[vfk vfv] (first 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))) (persistent! r)))
(meta v)))) (meta v))))


Expand Down
21 changes: 21 additions & 0 deletions src/test/clojure/clojure/core/logic/tests.clj
Expand Up @@ -1081,6 +1081,27 @@
(is (= (unifier '(?x 2 . ?y) '(1 9 3 4 5)) (is (= (unifier '(?x 2 . ?y) '(1 9 3 4 5))
nil))) 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 (deftest test-binding-map-1
(is (= (binding-map '(?x ?y) '(1 2)) (is (= (binding-map '(?x ?y) '(1 2))
'{?x 1 ?y 2}))) '{?x 1 ?y 2})))
Expand Down

0 comments on commit bd65104

Please sign in to comment.