back

by _doctor_love·10d ago·view on hn ↗
Will you share some insights on what Prolog is awesome for where a regular imperative language is not a good fit? I find both Prolog and Datalog very interesting in this new age of AI.
1 comments
Thank you a lot for your interest! Yes of course: As I see it, Prolog is often awesome in types of applications that are distinct from those one would usually build in other kinds of languages.

Alex Petros phrased it extremely nicely and insightfully in his comment at https://lobste.rs/s/0cvxwk/prolog_basics_explained_with_poke...:

"I don't know if this will be a satisfying answer to your question, but since writing this blog post I find myself reaching for Prolog in cases that are entirely orthogonal to any kind of code I used to write before. There are definitely people in the Prolog community who like using it for web servers or whatnot, but for me personally it's more about unlocking a different skill tree. For instance, I've become better at identifying where custom parsers or DSLs might be a good fit for a problem."

The mentioned blog post by Alex is available from: https://unplannedobsolescence.com/blog/prolog-basics-pokemon... and was recently discussed here: https://news.ycombinator.com/item?id=48147091

For another example, please see factgraph.pl also by Alex: https://github.com/alexpetros/factgraph.pl

Prolog is great in applications that must be able to analyze, extend, adapt, reason about and give account of their own workings and results. As an example for this, please see An Executable Specification of Oncology Dose-Escalation Protocols with Prolog by David C. Norris and me: https://arxiv.org/abs/2402.08334

In this example and others like it, one of the things the formulation is able to do is to tell us what the next step should be. And far, far beyond that, the same formulation can be used in many other ways, for instance to enumerate all cases that can arise, or to complete partially known cases, or to retroactively answer questions such as "Was the trial performed according to protocol?" We say we can use a logic program in different modes. And further, since a Prolog program is a sequence of Prolog terms, we can also use Prolog to easily read and analyze the formulation, and verify correctness or optimality properties of the formulation. Further, we can apply different execution strategies, including strategies that keep track of the reasons why specific results arose, and thus also produce automatic explanations of computed results.

Thank you! Beautiful answer.