datalog 2021-08-04

are there any resources on writing a datalog parser/query engine?

The datalog bnf can be translated to spec or malli (I have an example of the latter) You can then call parse/decode and bob's your uncle That takes care of parsing, at least

(by which I mean a datomic-like query syntax)

Not that I know of, but what would you like to know?

I sort of assume there's a theoretical starting point that would be useful if I wanted to write my own

You could start with my ClojureD talk from 2019?

I have been reading asami's source code but perhaps I'll begin again there 😄

It starts a bit simplistically, but gets into the “how”

but I think i'd like to write my own parser, to understand it better

Asami doesn’t actually parse. It just uses Clojure structures

tweaks this a little to form the AST, does some algebra and reordering on it, and then executes it

that's essentially what I want to do, I think

If you look at Asami, I recommend going back to an earlier iteration

that did joins and filters only, but it was much easier to follow

once you have that, then the latest code will make much more sense

I was getting a bit lost this morning in the planner distinctions and how that effected everything

Also, the code I pointed you at doesn’t handle queries as you’re familiar with them. You’d be looking for the query function in code.clj line 294. After the storage object, this function takes 2 arguments: • output-pattern: this is the content of a :find clause and can be something like [?p ?v] • patterns: this is the content of a :where clause, and can be something like [?e :age ?a] [(> ?a 20)] [?e ?p ?v]

The plan-path function can be safely ignored. Just assume that the output plan value is the same as the input patterns value. It also returns resolution-map, but that’s a bit misleading. It’s just that the default planner used this map, and the first step of the query also happened to use this map, and I figured I could save myself a step by returning it and using it, rather than looking it up again.

yes… I wouldn’t look at that AT ALL 🙂

that just does the reordering

you can turn it off

(And we often do)