如果对于 defrel 和事实的弃用以及迁移到 pldb 的方式应该如何更改此代码,我们将不胜感激?
以下代码:
(defrel parent x y)
(facts parent ’[[dave kaylen]
[frank dave]])
(defn grandparent
[x y]
(fresh [z]
(parent x z)
(parent z y)))
;; In the REPL
user> (run* [q]
(fresh [x y]
(grandparent x y)
(== q [x y])))
;; Result
([frank kaylen])
答案 0 :(得分:8)
(ns your.ns.here
(:require [clojure.core.logic.pldb :as pldb]
[clojure.core.logic :refer :all]))
(pldb/db-rel parent p1 p2)
(def facts
(pldb/db
[parent 'dave 'kaylen]
[parent 'frank 'dave]))
(defn grandparent
[x y]
(fresh [z]
(parent x z)
(parent z y)))
(pldb/with-db facts
(doall (run* [q]
(fresh [x y]
(grandparent x y)
(== q [x y])))))
=> ([frank kaylen])
有关更多示例,请参阅core.logic源代码中的pldb tests