Skip to content

Instantly share code, notes, and snippets.

@swannodette
Last active August 29, 2015 14:05
Show Gist options
  • Save swannodette/181b8e264223d03a3265 to your computer and use it in GitHub Desktop.
Save swannodette/181b8e264223d03a3265 to your computer and use it in GitHub Desktop.
(ns pldb-ex.core
(:refer-clojure :exclude [==])
(:require [clojure.core.logic :as l
:refer [run run* fresh == membero nafc]]
[clojure.core.logic.pldb :as pldb]))
;sku(wun_1). sku(wun_2). sku(wun_3).
;
;booking(wun_1, monday).
;booking(wun_2, monday).
;booking(wun_1, tuesday).
;booking(wun_3, tuesday).
;booking(wun_2, thursday).
;booking(wun_1, friday).
;booking(wun_3, friday).
;booking(wun_2, saturday).
;booking(wun_3, saturday).
;
;available(Sku, Date) :-
;sku(Sku),
;Dates = [monday,tuesday,wednesday,thursday,friday,saturday],
;member(Date, Dates),
;not(booking(Sku, Date)).
(pldb/db-rel sku)
(pldb/db-rel booking)
(def facts
(pldb/db
[sku :wun1]
[sku :wun2]
[sku :wun3]
[booking :wun1 :monday]
[booking :wun2 :monday]
[booking :wun1 :tuesday]
[booking :wun3 :tuesday]
[booking :wun2 :thursday]
[booking :wun1 :friday]
[booking :wun3 :friday]
[booking :wun2 :saturday]
[booking :wun3 :saturday]))
(defn availableo []
(pldb/with-db facts
(run* [Sku date]
(sku Sku)
(membero date [:monday :tuesday :wednesday :thursday :friday])
(nafc booking Sku date))))
;; (availableo) =>
;; ([:wun2 :tuesday] [:wun3 :monday] [:wun2 :wednesday] [:wun2 :friday]
;; [:wun3 :wednesday] [:wun1 :wednesday] [:wun3 :thursday] [:wun1 :thursday])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment