Last active
October 24, 2019 09:33
-
-
Save kordano/39398882d99b46ebd61155fcb566872a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[datahike.api :as d]) | |
(def uri "datahike:mem://simple_recursion") | |
(d/delete-database uri) | |
(d/create-database uri :schema-on-read true) | |
(def conn (d/connect uri)) | |
(d/transact conn [{:db/id 1 | |
:ancestor 2} | |
{:db/id 2 | |
:ancestor 3} | |
{:db/id 3 | |
:ancestor 4}]) | |
(def rule '[[(ancestor ?e1 ?e2) | |
[?e1 :ancestor ?e2]] | |
[(ancestor ?e1 ?e2) | |
[?e1 :ancestor ?t] | |
(ancestor ?t ?e2)]]) | |
(d/q '[:find ?u1 ?u2 | |
:in $ % | |
:where (ancestor ?u1 ?u2)] | |
@conn | |
rule) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment