This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-23
Channels
- # aws-lambda (1)
- # bangalore-clj (3)
- # beginners (80)
- # boot (8)
- # clojars (1)
- # clojure (200)
- # clojure-dev (37)
- # clojure-greece (26)
- # clojure-italy (11)
- # clojure-norway (3)
- # clojure-russia (14)
- # clojure-spec (21)
- # clojure-uk (30)
- # clojurescript (50)
- # core-logic (10)
- # core-matrix (1)
- # cursive (15)
- # data-science (21)
- # datomic (45)
- # devcards (2)
- # emacs (4)
- # fulcro (12)
- # garden (2)
- # jobs (5)
- # juxt (1)
- # lambdaisland (1)
- # leiningen (4)
- # luminus (20)
- # lumo (26)
- # off-topic (33)
- # onyx (27)
- # parinfer (1)
- # pedestal (3)
- # perun (5)
- # re-frame (20)
- # reagent (27)
- # ring (1)
- # ring-swagger (21)
- # shadow-cljs (259)
- # spacemacs (14)
- # yada (3)
How can I get all the successions in the conde elements as below I need to store the values of z as a list. Similar to https://en.wikibooks.org/wiki/Prolog/Recursive_Rules where all the ancestors are listed
(defn route [x y]
(conde
[(c x y)]
[(fresh [z]
(c x z)
(route z y))]))
(def facts
(pldb/db
[c 'a 'b]
[c 'a 'x]
[c 'b 'c]
[c 'c 'd]
[c 'd 'e]))
(pldb/with-db facts
(run* [q]
(fresh [x y]
(== x 'a)
(== y 'e)
(route x y)
(== q (route x y)))))
I need the result as [[a b][b c][c d][d e]]
. Is it possible with core.logic ?It seems it's not possible with core.logic : https://stackoverflow.com/questions/12563351/listing-unique-dag-parents-with-core-logic?rq=1 . Can someone explain the answer where David Nolen points out passing it to set constructor ?
I’d have to think some, but a couple notes: First, goals are not functions that return values. (== q (route x y)) is nonsensical on core.logic.
@norman Thanks I am currently a newbie to core.logic and still trying to grasp it. I was trying to convert the Prolog examples of recursive relations to core.logic and also found the definition of relations using functions at https://github.com/swannodette/logic-tutorial/blob/master/src/logic_tutorial/tut1.clj#L18 and thought it's right to use functions as goals. The closest I have got to working is as below :
(run-db* facts [q]
(fresh [x]
(== x 'a)
(route x q))) ;; (x b c d e)