Live data from Hacker News

Ask HN: What are some interesting examples of Prolog?

news.ycombinator.com

1–10 of 64 posts

Ask HN: What are some interesting examples of Prolog?

#1
I'm trying to source some programs and libraries written in Prolog to gain a better understanding of how a complete application is put together. Lots of Hello, World-esque examples out there, but looking for things that are a little less trivial.

I did come across terminusdb: https://github.com/terminusdb/terminusdb which looks interesting.

Any other codebases people would recommend that are worth a read?

Re: Ask HN: What are some interesting examples of Prolog?

#2
Not exactly a big codebase, but it was a revelation for me how natural typecheckers can feel in Prolog: I basically rewrote typing rules with some tweaks: [1]

Also, tests were surprisingly enjoyable in Prolog: [2].

[1] https://github.com/EarlGray/language-incubator/blob/29755c32... [2] https://github.com/EarlGray/language-incubator/blob/29755c32...

Re: Ask HN: What are some interesting examples of Prolog?

#5
One of the most interesting applications of Prolog I have seen in the recent past is the formalization of dose-escalation trial designs that occur in clinical oncology. In particular, David C. Norris has implemented a Prolog formulation of the cumulative cohort design (CCD) as part of his precautionary package:

https://github.com/dcnorris/precautionary/blob/main/exec/pro...

This Prolog program can be used to exhaustively enumerate all possible arising cases, and also to complete partially given trials. In addition to the specific usage mode of telling the clinician what action to perform next after a sequence of events has occurred, it is also possible to ask interesting questions about the trial design as a whole, such as whether specific cases can arise at all, or whether a specific instance was performed according to the protocol. In this sense, the formulation truly serves as an executable specification of trial designs that are otherwise stated only comparatively informally in the medical literature, and may even be subject to divergent interpretations. The formulation uses Scryer Prolog and the latest Prolog language constructs (such as if_/3 and CLP(ℤ) constraints) to achieve a short and very general description. Such declarative specifications may help considerably to improve safety and efficiency of clinical trials, by making all steps and outcomes amenable to analysis and comparison.

Theorem provers and reasoning engines are also often implemented in Prolog. A recent example is solidarity by Jos De Roo:

https://github.com/josd/solidarity

Prolog is also frequently used for prototyping interpreters. For example, Adrián Arroyo Calle is working on a MIPS simulator written in Prolog:

https://github.com/aarroyoc/mipsie

Simon Forman has implemented a Prolog interpreter of Joy in which, remarkably, the declarative description also serves as a type inferencer and type checker:

https://git.sr.ht/~sforman/Thun/tree/master/item/source/thun...

Porting this code to Scryer Prolog could be an interesting project if it appeals to you. There is already an issue for it and pertaining discussion:

https://github.com/mthom/scryer-prolog/issues/388

Re: Ask HN: What are some interesting examples of Prolog?

#8
post #2

Not exactly a big codebase, but it was a revelation for me how natural typecheckers can feel in Prolog: I basically rewrote typing rules with some tweaks: [1] Also, tests were surprisingly enjoyable in Prolog: [2]. [1] https://github.com/EarlGray/language-incubator/blob/29755c32... [2] https://github.com/EarlGray/language-incubator/blob/29755c32...

Not a criticism of the code here by any stretch, I always find it impressive when people manage to understand languages that are totally foreign to me, that being said however Prolog has always struck me as uniquely unreadable. Even back in university when we looked briefly at different styles of programming, the code always ended up looking something like lines 107-132 in your example, which to someone jumping in is pretty much indecipherable.

Is anyone aware of any higher level abstractions for logic based languages that is actually used in industry? From what I’ve seen in the various banks and fintech groups I’ve worked with, prolog itself was very rarely if ever used ‘in anger’, but I have heard of it being used for automation so I’m very curious what that looks like.

Post reply on HN