Skip to content

Commit

Permalink
Merge pull request #11 from orb/tostream
Browse files Browse the repository at this point in the history
don't use core.logic to-stream
  • Loading branch information
orb committed Jun 23, 2013
2 parents 6dcd376 + d07bbda commit 8e8036f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
15 changes: 11 additions & 4 deletions src/pldb/logic.clj
@@ -1,5 +1,6 @@
(ns pldb.logic (ns pldb.logic
(:require [clojure.core.logic :as l])) (:require [clojure.core.logic :as l]
[clojure.core.logic.protocols :as proto]))




;; ---------------------------------------- ;; ----------------------------------------
Expand Down Expand Up @@ -46,6 +47,14 @@
:when (and indexable indexed)] :when (and indexable indexed)]
i)))) i))))



;; replacement for core.logic to-stream, which calls unify, but doesn't do
;; everything == does
(defn stream-unified [s v vals]
(when (seq vals)
(proto/mplus (proto/bind s (l/== v (first vals)))
(fn [] (stream-unified s v (rest vals))))))

(defmacro db-rel [name & args] (defmacro db-rel [name & args]
(let [arity (let [arity
(count args) (count args)
Expand All @@ -65,9 +74,7 @@
index# index#
(l/walk* subs# (nth query# index#))) (l/walk* subs# (nth query# index#)))
(facts-for ~kname))] (facts-for ~kname))]
(l/to-stream (map (fn [potential#] (stream-unified subs# query# facts#))))
(l/unify subs# query# potential#))
facts#)))))
{:rel-name ~kname {:rel-name ~kname
:indexes ~indexes})))) :indexes ~indexes}))))


Expand Down
7 changes: 3 additions & 4 deletions test/pldb/logic_test.clj
Expand Up @@ -28,7 +28,7 @@


(deftest test-facts0 (deftest test-facts0
( pldb/with-db facts0 ( pldb/with-db facts0
(is (= (is (=
(l/run* [q] (l/run* [q]
(l/fresh [x y] (l/fresh [x y]
(likes x y) (likes x y)
Expand All @@ -38,7 +38,7 @@


(deftest test-facts1 (deftest test-facts1
(pldb/with-db facts1 (pldb/with-db facts1
(is (= (is (=
(l/run* [q] (l/run* [q]
(l/fresh [x y] (l/fresh [x y]
(likes x y) (likes x y)
Expand All @@ -65,7 +65,7 @@


(deftest test-rel-logic-29 (deftest test-rel-logic-29
(pldb/with-db indexed-db (pldb/with-db indexed-db
(is (= (is (=
(l/run* [q] (l/run* [q]
(l/fresh [a] (l/fresh [a]
(rel1 [q a]) (rel1 [q a])
Expand Down Expand Up @@ -209,4 +209,3 @@
(protocol :https https-port) (protocol :https https-port)
(open-port ip http-port) (open-port ip http-port)
(open-port ip https-port)))))))) (open-port ip https-port))))))))

0 comments on commit 8e8036f

Please sign in to comment.