Last active
February 16, 2017 05:48
-
-
Save daveduthie/f91dc1c9587daacbba50f6b656bb8cab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns schejule.core | |
(:require [clojure.core.logic :as lg] | |
[clojure.core.logic.pldb :as pldb])) | |
;; Declare database relations | |
(pldb/db-rel tasko ^:index id) | |
(pldb/db-rel precedo ^:index id other-id bool) | |
;; Make example db | |
(def mini-db | |
(-> (pldb/db) | |
(pldb/db-fact tasko 1) | |
(pldb/db-fact tasko 2) | |
(pldb/db-fact tasko 3) | |
(pldb/db-fact tasko 4) | |
(pldb/db-fact precedo 1 2 0) | |
(pldb/db-fact precedo 1 3 0) | |
(pldb/db-fact precedo 1 4 0) | |
(pldb/db-fact precedo 2 1 1) | |
;; (pldb/db-fact precedo 2 3 0) <--- precedence missing here | |
(pldb/db-fact precedo 2 4 0) | |
(pldb/db-fact precedo 3 1 1) | |
(pldb/db-fact precedo 3 2 1) | |
(pldb/db-fact precedo 3 4 0) | |
(pldb/db-fact precedo 4 1 1) | |
(pldb/db-fact precedo 4 2 1) | |
(pldb/db-fact precedo 4 3 1))) | |
;; Try to bind q to task with missing precedence | |
(pldb/with-db mini-db | |
(lg/run* [q] | |
(lg/fresh [x y z] | |
(tasko q) | |
(precedo x y z) | |
(lg/!= q x)))) | |
;; This fails because whatever x unifies to, | |
;; there are 3 other values that q can take. | |
;; Thus, q unifies with the full range of tasks. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment