I have a somewhat unusual question: Given an AST for a programming language in a Datascript db, is it possible to identify dependencies with their db id, if all dependencies are db.type/ref
? One problem I see is that they might not be immediate children of the node, but further down the tree. I know that datalog supports recursive queries, but my datalog-fu isn't strong enough for that (yet) 😉
The nodes are quite inhomogeneous (It's not a lisp tree sadly), so enumerating all possibilities by hand would be somewhat tedious, but theoretically possible
Maybe some inspiration? https://stackoverflow.com/questions/42457136/recursive-datalog-queries-for-datomic-really-slow
Actually this is a better example: https://github.com/tonsky/datascript/blob/1661c524b544fa0c212bc2db65ef7ad22cecb319/test/datascript/test/pull_api.cljc#L212
Cool, thanks, will check
Ah, actually the frontpage itself has a good example too:
(d/q '[ :find ?u1 ?u2
:in $ %
:where (follows ?u1 ?u2) ]
[ [1 :follows 2]
[2 :follows 3]
[3 :follows 4] ]
'[ [(follows ?e1 ?e2)
[?e1 :follows ?e2]]
[(follows ?e1 ?e2)
[?e1 :follows ?t]
(follows ?t ?e2)] ])
I was looking for something like that, coding it to a custom ruleI would expect that the pull based queries to have some issues dealing with cases where there can be more intermediate immediate steps with different child attributes
I found that I can generate this rule from the schema, that's pretty awesome 😈