Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Failing zebra test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakan Raberg committed Oct 10, 2012
1 parent 1800361 commit 2cb8204
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/mimir/mk.clj
Expand Up @@ -125,8 +125,9 @@
(postwalk cons-pairs-to-seqs (postwalk-replace vs xs)))) (postwalk cons-pairs-to-seqs (postwalk-replace vs xs))))


(defmacro run* [[& x] & g] (defmacro run* [[& x] & g]
`(binding [*match-var?* var?] (let [g (postwalk-replace {'_ '(mimir.mk.LVar. (gensym '_))} g)]
(run-internal (fresh [~@x] ~@g (partial reify-goal ~(vec x))) [{}]))) `(binding [*match-var?* var?]
(run-internal (fresh [~@x] ~@g (partial reify-goal ~(vec x))) [{}]))))


(defmacro run [n [& x] & g] (defmacro run [n [& x] & g]
`(take ~n (run* [~@x] ~@g))) `(take ~n (run* [~@x] ~@g)))
Expand Down
70 changes: 68 additions & 2 deletions test/mimir/test/mk.clj
Expand Up @@ -229,8 +229,7 @@
(run* [x q] (run* [x q]
(consᵒ 1 x q) (consᵒ 1 x q)
(restᵒ q x)) (restᵒ q x))
⇒ '(–₀ (1 . –₀)) ⇒ '(–₀ (1 . –₀))))
))


(deftest memberᵒ-the-divergent (deftest memberᵒ-the-divergent
(are [a _ e] (is (= a e)) (are [a _ e] (is (= a e))
Expand Down Expand Up @@ -307,4 +306,71 @@
;; (1 2 3 4 5) (1 2) (2 3 4 5) (4) (3 4 5) (1 2 3 4) (5)} ;; (1 2 3 4 5) (1 2) (2 3 4 5) (4) (3 4 5) (1 2 3 4) (5)}
)) ))


(deftest anonymous-vars
(is (= (run* [q] ( q _)) '(–₀))))

;; From https://github.com/swannodette/logic-tutorial
(deftest zebra
(defn rightᵒ [x y l]
(condᵉ
((prefixᵒ [x y] l))
((fresh [d]
(restᵒ l d)
(rightᵒ x y d)))))

(defn nextᵒ [x y l]
(condᵉ
((rightᵒ x y l))
((rightᵒ y x l))))

(are [a _ e] (is (= a e))

(run* [q]
(rightᵒ 1 2 [1 2]))
⇒ '(–₀)

(run* [q]
(rightᵒ 1 2 [0 1 2 3]))
⇒ '(–₀)

(run* [q]
(rightᵒ 1 2 [1]))
⇒ '()

(run* [q]
(rightᵒ 1 2 [0 1 3 2 3]))
⇒ '()

(run* [q]
(nextᵒ 1 2 [3 2 1]))
⇒ '(–₀)

(run* [q]
(nextᵒ 1 2 [1 3 2]))
⇒ '())

;; Doesn't run yet, small subsets "work".
;; (is (= (run 1 [hs]
;; (≡ [_ _ [_ _ 'milk _ _] _ _] hs)
;; (firstᵒ hs ['norwegian _ _ _ _])
;; (nextᵒ ['norwegian _ _ _ _] [_ _ _ _ 'blue] hs)
;; (rightᵒ [_ _ _ _ 'ivory] [_ _ _ _ 'green] hs)
;; (memberᵒ ['englishman _ _ _ 'red] hs)
;; (memberᵒ [_ 'kools _ _ 'yellow] hs)
;; (memberᵒ ['spaniard _ _ 'dog _] hs)
;; (memberᵒ [_ _ 'coffee _ 'green] hs)
;; (memberᵒ ['ukrainian _ 'tea _ _] hs)
;; (memberᵒ [_ 'lucky-strikes 'oj _ _] hs)
;; (memberᵒ ['japanese 'parliaments _ _ _] hs)
;; (memberᵒ [_ 'oldgolds _ 'snails _] hs)
;; (nextᵒ [_ _ _ 'horse _] [_ 'kools _ _ _] hs)
;; (nextᵒ [_ _ _ 'fox _] [_ 'chesterfields _ _ _] hs))

;; '([[norwegian kools –₀ fox yellow]
;; [ukrainian chesterfields tea horse blue]
;; [englishman oldgolds milk snails red]
;; [spaniard lucky-strikes oj dog ivory]
;; [japanese parliaments coffee –₁ green]])))
)

(alter-var-root #'*match-var?* (constantly mv)) (alter-var-root #'*match-var?* (constantly mv))

0 comments on commit 2cb8204

Please sign in to comment.