Would appreciate any help on how this code should be changed with regards to the deprecation of defrel and facts and the move to pldb?
Here's the code:
(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])    
(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])
See the pldb tests from core.logic source for more examples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With