This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-10
Channels
- # aleph (4)
- # aws (2)
- # bangalore-clj (2)
- # beginners (84)
- # boot (25)
- # cider (3)
- # cljsrn (3)
- # clojure (57)
- # clojure-italy (5)
- # clojure-losangeles (3)
- # clojure-russia (7)
- # clojure-spec (18)
- # clojure-uk (29)
- # clojurescript (90)
- # cursive (11)
- # data-science (68)
- # datascript (2)
- # datomic (25)
- # duct (3)
- # fulcro (13)
- # graphql (7)
- # immutant (1)
- # jobs (1)
- # leiningen (12)
- # lumo (1)
- # off-topic (51)
- # om (43)
- # onyx (15)
- # parinfer (10)
- # pedestal (4)
- # re-frame (7)
- # reagent (42)
- # ring-swagger (42)
- # rum (1)
- # shadow-cljs (172)
- # spacemacs (10)
- # specter (4)
- # sql (4)
- # test-check (19)
- # unrepl (54)
- # yada (3)
Given a directed acyclic graph (where each node has optional :node/parent
), how do I recursively fetch the IDs of all descendant nodes with a Datalog query? I spent about 40 minutes trying to find an example in Datascript code and Datalog, but couldn’t find anything
Got it working (using Posh and abusing square bracket rule). It doesn’t auto-update unfortunately, but OK for my use-case:
@(p/q '[:find ?c
:in $ % ?parent
:where
[child ?c ?parent]]
conn
'[[(child ?c ?p)
(?c :parent ?p)]
[(child ?c ?p)
(?c1 :parent ?p)
(child ?c ?c1)]]
parent-id)
Am I doing it right?