Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #11 from orb/tostream

don't use core.logic to-stream
  • Loading branch information...
commit 8e8036fa0fedca7bb6ccee4af41a2bf6a66ffc2b 2 parents 6dcd376 + d07bbda
@orb orb authored
Showing with 14 additions and 8 deletions.
  1. +11 −4 src/pldb/logic.clj
  2. +3 −4 test/pldb/logic_test.clj
View
15 src/pldb/logic.clj
@@ -1,5 +1,6 @@
(ns pldb.logic
- (:require [clojure.core.logic :as l]))
+ (:require [clojure.core.logic :as l]
+ [clojure.core.logic.protocols :as proto]))
;; ----------------------------------------
@@ -46,6 +47,14 @@
:when (and indexable indexed)]
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]
(let [arity
(count args)
@@ -65,9 +74,7 @@
index#
(l/walk* subs# (nth query# index#)))
(facts-for ~kname))]
- (l/to-stream (map (fn [potential#]
- (l/unify subs# query# potential#))
- facts#)))))
+ (stream-unified subs# query# facts#))))
{:rel-name ~kname
:indexes ~indexes}))))
View
7 test/pldb/logic_test.clj
@@ -28,7 +28,7 @@
(deftest test-facts0
( pldb/with-db facts0
- (is (=
+ (is (=
(l/run* [q]
(l/fresh [x y]
(likes x y)
@@ -38,7 +38,7 @@
(deftest test-facts1
(pldb/with-db facts1
- (is (=
+ (is (=
(l/run* [q]
(l/fresh [x y]
(likes x y)
@@ -65,7 +65,7 @@
(deftest test-rel-logic-29
(pldb/with-db indexed-db
- (is (=
+ (is (=
(l/run* [q]
(l/fresh [a]
(rel1 [q a])
@@ -209,4 +209,3 @@
(protocol :https https-port)
(open-port ip http-port)
(open-port ip https-port))))))))
-
Please sign in to comment.
Something went wrong with that request. Please try again.