Skip to content

Instantly share code, notes, and snippets.

@kordano
Last active October 24, 2019 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kordano/39398882d99b46ebd61155fcb566872a to your computer and use it in GitHub Desktop.
Save kordano/39398882d99b46ebd61155fcb566872a to your computer and use it in GitHub Desktop.
(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