99 points · by triska · 5y ago · 20 comments
As it stands, quering (pseudocode) "connect(C), insert(C, data), false" has no solution but side-effects.
SLD-resolution probably just does not work with side-effects.
Of course, that's hard to do when interacting with external systems!
I do think consensus algorithms have something deeply in common here, as CALM (Consistency As Logical Monotonicity) seems to cover the space of join-semilattice structures pretty crisply, and CALM is all about when you don't need consensus. But again, just my own musings.
And then you just write down all the rules.
edit: As long as queries aren't recursive in a difficult manner, like co-recursive or have multiple recursive calls in the same rule.
It has first-class Datalog constraints as a language feature!
As being a FP language it's of course good at modeling data. At the same time it's fast enough for heavy tasks: It runs on the JVM, having also access to its rich ecosystem.
For example, the string "abc" takes only 4 bytes in this representation, and the unification "abc" = [a,b,c] succeeds. Indeed, we have:
?- write_canonical("abc").
'.'(a,'.'(b,'.'(c,[]))) true.
On 64-bit systems, a conventional internal representation of "abc" as the compound term .(a, .(b, .(c, []))) takes 8 bytes per functor (each '.'/2 takes 8 bytes, i.e., 1 cell in the WAM), 8 bytes per character (as a pointer to the atom table, again 1 cell in the WAM), and 8 bytes for each tail. All Prolog systems before Scryer Prolog use 16 to 24 times as much memory to represent a list of characters. As of recent, Trealla Prolog also uses the efficient representation, at least for fully instantiated strings. Scryer Prolog can also represent partial strings such as [a,b,c|Ls] with the efficient encoding.