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.
If this is easily double you’d need:
(route r x y) which asserts r is a route between x and y
given the provided facts
Then you’d assert (route q ’a ’e)
Otherwise you can’t generate the path, only the fact that a path exists
@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)
Yes, that route is just a fact that asserts a route exists