Suggestions for a more elaborate Hello World example
I suggest adding a tad bit more advanced hello world example, to quickly get people to understand how to register facts, and to query them with an advanced query.
I don't know (yet) how to represent this in cozo, but in Prolog, I often do something like this (might make some syntax mistake, but I hope you get the idea):
So, saving this into facts.pl
parent(joseph, jakob).
parent(jakob, isaac).
parent(isaac, abraham).
grandparent(Grandchild, Grandparent) :-
parent(Grandchild, Middleperson),
parent(Middleperson, Grandparent).
... and then running this in a swipl shell:
?- grandparent(jakob, Who).
Who = abraham.
?- grandparent(joseph, Who).
Who = isaac.
?-
To me, this shows:
- How to assert facts that are relations
- How to define queries based on relation facts
- How to query this query with different inputs
Do you think something similar would make sense as a hello world example for cozo?
I think the example you provided is much better than what we currently have. The documentation is currently all over the place, will fix that when I get to work on it.
For the equivalent query in Cozo, if you want everything inline:
parent[] <- [['joseph', 'jakob'],
['jakob', 'issac'],
['issac', 'abraham']]
grandparent[gcld, gp] := parent[gcld, p], parent[p, gp]
?[who] := grandparent[who, 'abraham']
You can also define parent and grandparent to be stored relations (persistent on disk, similar to tables in SQL), and have triggers update grandparent when you change parent.
For the equivalent query in Cozo, if you want everything inline:
Oh, this is great, thanks a lot! :+1:
In fact, I since found the tutorial, which I think served to some extent to fill in those gaps, although also I tend to like hello world examples that show some of they key mechanisms even there, if possible.
Keep up the great work!
The new README https://github.com/cozodb/cozo/commit/2c872e6982a652ea194a1b68c3c95629b44daa6e still contains the "teasers" examples, but finding the relevant information should now be easier.