Fork me on GitHub
#datascript
<
2018-11-02
>
mrchance02:11:26

Ok, I got considerably further, but now I want to write a rule to get all dependency-graph edges relevant for a particular id. I wrote

[(dep-for ?p ?a ?b)
      [(= ?p ?a)]
      (depends ?a ?b)]
     [(dep-for ?p ?a ?b)
      (depends ?p ?a)
      (depends ?a ?b)]
but it only returns matches for the second definition of dep-for, so I suspect that there's something wrong with my use of = here. Any idea what it might be?

mrchance02:11:37

I feel like I'm missing something obvious

bahulneel15:11:22

You need some kind of recursion

bahulneel15:11:21

here's the classic example

bahulneel15:11:27

[(ancestor ?a ?b)
 (parent ?a ?b)]
[(ancestor ?a ?b)
 (parent ?a ?c)
 (ancestor ?c ?b)]

mrchance16:11:24

Thanks for replying, but I don't think it solves the problem I had, if you check my code, I have almost exactly the same structure, but what I need, in your example, is the list of all parent/child pairs, where the parent is either me or a descendant of me

bahulneel16:11:11

What are ?p, ?a and ?b in dep-for

bahulneel16:11:23

Also the difference between what I have and you is that you don't recur back to dep-for

bahulneel16:11:39

Also ?b is unbound in you first rule

mrchance10:11:56

Yes, but that's deliberate, I want all pairs ?a ?b where ?a is a parent of ?b and either identical or a descendant of ?p

mrchance10:11:03

Why is it unbound? It's used in the body? Maybe it helps when I post the full code, will do that later when I'm back home

ClashTheBunny12:11:31

Does order matter? I feel like a question or two in learndatalogtoday were only wrong based on order of the statements. That doesn't make sense to me though...

metasoarous21:11:19

Order shouldn't matter except as relates to performance details (which queries get run first, thereby reducing the amount of downstream query work which has to be done), at least as far as Datomic goes.

mrchance12:11:14

Hm, as far as I understood it, that only matters performance-wise and should not influence the result set

isak20:11:12

is it possible to filter on :db/id in :where with datalog queries ? Looks like no - I always get an empty result set if I do. Is there an alternative?

metasoarous21:11:32

I guess I've never tried, but I would have expected it to work; Would be interesting to see what Datomic does here. In any case, you should basically never need to do this; If [?e :db/id ?id] matches a triple, then indeed, (= ?e ?id), so you can replace with [?e].

metasoarous21:11:55

Which raises the question: why would you want to do this?

metasoarous21:11:11

If ?e is being bound as a query input, then you already know what the eid is.

metasoarous21:11:05

If it's being bound from another relation, like [?a :friend ?e], then why do you also need [?e] as a separate relation? You already know what the eid is; it's ?e!

isak21:11:12

@U05100J3V makes sense, thanks for the help. Changing it be a query input made it work.