Hacker News new | ask | show | jobs
by triska 2958 days ago
Prolog and Datalog also have a lot in common: In addition to Datalog being a syntactic subset of Prolog, the semantics of Prolog and Datalog, and hence the solutions you obtain, are also identical if you enable SLG resolution in your Prolog system and run a Datalog program with it.

SLG resolution (also called "tabling" in Prolog) prevents both positive and negative loops, and always terminates for programs that have the bounded term-size property, as is the case for all Datalog programs. XSB Prolog is a notable example of a Prolog system that supports this mode, which you can enable with the table/1 directive:

http://xsb.sourceforge.net/shadow_site/manual1/node2.html

Therefore, you can use a Prolog system such as XSB Prolog also to learn Datalog, and then seamlessly move to Prolog. Conversely, if you know Prolog, then learning Datalog is very easy. Another very nice system for learning Datalog is DES, which you can run in SICStus Prolog and other systems:

http://des.sourceforge.net/

Various extensions such as aggregate functions and object-oriented programming (which are mentioned in the Wikipedia entry for Datalog) are also applicable to both Prolog and Datalog with identical or closely related semantics.

1 comments

Yes, I'm well aware of tabling, which is why I said "naïve Prolog implementation". I'm also aware of using magic sets and demand transformations to allow writing Prolog-like relations in Datalog.

I also work on an industrial strength Datalog implementation and I can tell you unequivocally there is very little relationship with how a real Datalog engine is implemented and a Prolog implementation.

And no, learning Prolog will not help you learn Datalog. Unless you're going to always us tabling or demand transformations, the difference in evaluation model requires writing in a very different style.

Yes, such implementation differences definitely exist!

Whether one emphasizes the differences or commonalities of Prolog and Datalog may also depend on commercial interests: For vendors of Datalog systems, it may be advantageous to stress the differences. For Prolog vendors, it may conversely be advantageous to stress their commonalities.

Personally, I learned Prolog before Datalog, and it was easy for me to learn Datalog because I was already familiar with Prolog. The reason may be that I try to write as declaratively as possible when programming in Prolog, and that carried over well to Datalog too. More recently, I have also used tabling in many Prolog programs, and often obtained very general programs with good termination properties, similar to Datalog definitions.