4

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])    
CC BY-SA 3.0

1 Answer 1

11
(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

CC BY-SA 3.0
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.