Skip to content

Commit

Permalink
* src/main/cljs/cljs/core/logic.cljs: walk tests
Browse files Browse the repository at this point in the history
  • Loading branch information
David Nolen authored and David Nolen committed Mar 25, 2012
1 parent c7d88d1 commit bbc72f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main/cljs/cljs/core/logic.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@
(defn subst? [x]
(instance? Substitutions x))

(defn to-s [v]
(let [s (reduce (fn [l [k v]]
(cons (pair k v) l))
() v)]
(make-s s)))

;; =============================================================================
;; Logic Variables

Expand Down
18 changes: 17 additions & 1 deletion src/test/cljs/cljs/core/logic/tests.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:only [run run* == conde fresh defne matche]])
(:use
[cljs.core.logic
:only [pair lvar lcons -unify -ext-no-check empty-s]]))
:only [pair lvar lcons -unify -ext-no-check -walk empty-s to-s]]))

(set! *print-fn* js/print)

Expand Down Expand Up @@ -346,4 +346,20 @@
d (lvar 'd)]
(assert (= (-unify empty-s #{a b 9 4 5} #{1 2 3 c d}) false)))

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

(assert
(= (let [x (lvar 'x)
y (lvar 'y)
s (to-s [[x 5] [y x]])]
(-walk s y))
5))

(assert
(= (let [[x y z c b a :as s] (map lvar '[x y z c b a])
s (to-s [[x 5] [y x] [z y] [c z] [b c] [a b]])]
(-walk s a))
5))

(println "ok")

0 comments on commit bbc72f8

Please sign in to comment.