-
Notifications
You must be signed in to change notification settings - Fork 9
/
tp.clj
33 lines (29 loc) · 802 Bytes
/
tp.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(ns logically.abs.tp
(:refer-clojure :exclude [==])
(:use [clojure.core.logic :exclude [is] :as l]
[clojure.core.logic.nominal :exclude [fresh hash] :as nom])
(:use [logically.abs.db]
[logically.abs.lub]))
(defn prove [db flag goals]
(conde
[(fresh [b bs]
(conso b bs goals)
(db-get-fact db b)
(prove db flag bs))]
[(== goals ())]))
(defn operatoro [db flag c]
(fresh [head body]
(c head body)
(prove db flag body)
(set-union db flag head)))
(defn iterateo [db flag c]
(conda
[(all (operatoro db flag c) fail)]
[(all (flag-retract! flag) (iterateo db flag c))]
[succeed]))
(defn go [c q]
(let [db (db-new)
flag (flag-new)]
(all
(iterateo db flag c)
(db-get-fact db q))))