Porting the "Worst Datalog" to Python
I really enjoyed the two posts by Christophe Grand about Datalog, Writing the Worst Datalog Ever in 26loc and Half Dumb Datalog in 30 loc (even more than the first one), so I ended up porting them to Python.
There's a bunch of differences to the Clojure versions:
- they are roughly twice as long
- use generators and thus have to environment threading somewhat differently
- a custom class for variables (no symbols in Python)
- some dictionary copying is going on because of mutability (and I didn't want to think too much about when mutation is happening).
The semi-naive implementation ended up being roughly 50 lines, which is pretty reasonable I thought.
The code for them both is in this Gist: