Fork me on GitHub
#datascript
<
2019-05-17
>
urzds10:05:40

Does DataScript have a set difference operator?

urzds10:05:16

i.e. every element of result set A that is not also in result set B?

Daniel Hines12:05:05

In this rule:

[(subproject-or-self ?e1 ?e2)
     [?e1]
     (subproject ?e1 ?e2)]]
What does [?e1] do? I’ve yet to encounter that syntax in my limited experimentations with Datascript.

urzds15:05:09

@d4hines The intention was that subproject-or-self evaluates to either ?e1 or subprojects thereof.

urzds15:05:28

Though I just realise it should be [?e2] instead.

Daniel Hines16:05:36

@urzds What does that [ ] syntax do?

Daniel Hines16:05:54

Does it just fill in attribute and value with blanks?

urzds16:05:22

@d4hines I believe so. I just took the recursive example from the datascript readme and adapted it to my needs as appeared logical to me. Lucky me: It worked. 😉

urzds16:05:23

I think rules exist to create relations automatically? So [?e1] is a relation. The one with AVT=blank. That's how I understand it, without being an expert.

Daniel Hines16:05:20

That’s definitely how I would read that, but what does [?e1 _ _] buy you? That there’s an entity with that id? isn’t that implicit in the query?

urzds16:05:22

Well, I can tell you that (subproject ?e ?existing-project) finds you all subprojects ?e, but not including ?existing-project.

urzds16:05:47

So I added another rule that would also match ?existing-project in addition to the subprojects the other rule found. I kept subproject and subproject-or-self separate in order to prevent funny stuff from happening (infinite recursions?), without having a specific reason.

Daniel Hines16:05:17

I guess I’m not convinced that this query:

[(subproject-or-self ?e1 ?e2)
     [?e2]
     (subproject ?e1 ?e2)]]
could ever return a different set than this query:
[(subproject-or-self ?e1 ?e2)
     (subproject ?e1 ?e2)]]
Or indeed, that the addition of any form with the pattern [?e] could ever change any result set.

Daniel Hines16:05:41

And I’m interested because if I’m wrong, I need to reevaluate how I think queries…evaluate.

urzds16:05:15

Maybe I really should write some tests that check these assumptions...

urzds16:05:26

How else would you answer my question from yesterday? How to make ?project the union of ?top-level-project and some list of [?subproject]s?

Daniel Hines17:05:24

I would have tried

[(or [?project :unique-id ?top-level-project-id]   (subproject ?project ?top-level-project-id)]

Daniel Hines17:05:40

But I’m new at this - that’s just a hunch.

Daniel Hines17:05:54

You’ve gotta just try this at the REPL.

urzds17:05:11

I think I got error messages regarding unbound variables when I did it with or. So I tried or-join, but that resulted in what I posted above.

Daniel Hines17:05:36

Gotcha. Reading, the docs on or-join, that makes sense now. This has been a helpful excursion - thanks for sharing it with us!

Daniel Hines17:05:10

It’s probably just so much spam for the ol’ timers, but I know I learned something 😛