TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: What are some interesting examples of Prolog?

198 pointsby hazboabout 3 years ago
I&#x27;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.<p>I did come across terminusdb: https:&#x2F;&#x2F;github.com&#x2F;terminusdb&#x2F;terminusdb which looks interesting.<p>Any other codebases people would recommend that are worth a read?

36 comments

triskaabout 3 years ago
One of the most interesting applications of Prolog I have seen in the recent past is the formalization of <i>dose-escalation trial designs</i> 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 <i>precautionary</i> package:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;dcnorris&#x2F;precautionary&#x2F;blob&#x2F;main&#x2F;exec&#x2F;prolog&#x2F;ccd.pl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dcnorris&#x2F;precautionary&#x2F;blob&#x2F;main&#x2F;exec&#x2F;pro...</a><p>This Prolog program can be used to exhaustively <i>enumerate</i> all possible arising cases, and also to <i>complete</i> 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 <i>executable specification</i> 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_&#x2F;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.<p>Theorem provers and reasoning engines are also often implemented in Prolog. A recent example is <i>solidarity</i> by Jos De Roo:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;josd&#x2F;solidarity" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;josd&#x2F;solidarity</a><p>Prolog is also frequently used for prototyping <i>interpreters</i>. For example, Adrián Arroyo Calle is working on a MIPS simulator written in Prolog:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;aarroyoc&#x2F;mipsie" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;aarroyoc&#x2F;mipsie</a><p>Simon Forman has implemented a Prolog interpreter of <i>Joy</i> in which, remarkably, the declarative description also serves as a type inferencer and type checker:<p><a href="https:&#x2F;&#x2F;git.sr.ht&#x2F;~sforman&#x2F;Thun&#x2F;tree&#x2F;master&#x2F;item&#x2F;source&#x2F;thun.pl" rel="nofollow">https:&#x2F;&#x2F;git.sr.ht&#x2F;~sforman&#x2F;Thun&#x2F;tree&#x2F;master&#x2F;item&#x2F;source&#x2F;thun...</a><p>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:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;mthom&#x2F;scryer-prolog&#x2F;issues&#x2F;388" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mthom&#x2F;scryer-prolog&#x2F;issues&#x2F;388</a>
评论 #31212056 未加载
ggleasonabout 3 years ago
TerminusDB CTO here.<p>Echoing what triska said, CLP(ℤ) and friends are some of the most under-appreciated aspects of prolog implementations.<p>I&#x27;m amazed that programmers still don&#x27;t have access to CLP when trying to do scheduling and planning solutions.<p>As an example in practice, what if you want to know about a transaction in which a number of entities transitively had holdings in one of the beneficiaries of the transaction at that particular time. The date window is not known, and the date windows are important in the ownership chain as well as the transactions that are being undertaken.<p>With CLP(FD) you can ask for <i>a</i> window of time, and the solution will zoom in on an appropriate time window which exists for the entire chain and match the time of the transaction.<p>Now try to do this query in SQL. It&#x27;s almost impossibly hard.<p>I can&#x27;t wait until I have the time to implement constraint variables for TerminusDB, but at the minute we are still working on more prosaic features.<p>Aside from that there are very interesting program correctness and optimisation systems which are based on prolog (usually a datalog). For instance Soufflé: <a href="https:&#x2F;&#x2F;souffle-lang.github.io" rel="nofollow">https:&#x2F;&#x2F;souffle-lang.github.io</a>
ipnonabout 3 years ago
There exists a formulation of the Japanese Constitution in Prolog, which can then be called with a proposition to determine its constitutionality.
评论 #31211957 未加载
dmytrishabout 3 years ago
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]<p>Also, tests were surprisingly enjoyable in Prolog: [2].<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;EarlGray&#x2F;language-incubator&#x2F;blob&#x2F;29755c32edc631d3a296d06242e0e339b24453db&#x2F;fp&#x2F;tapl&#x2F;fullsimple.pl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;EarlGray&#x2F;language-incubator&#x2F;blob&#x2F;29755c32...</a> [2] <a href="https:&#x2F;&#x2F;github.com&#x2F;EarlGray&#x2F;language-incubator&#x2F;blob&#x2F;29755c32edc631d3a296d06242e0e339b24453db&#x2F;fp&#x2F;tapl&#x2F;fullsimple.plt" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;EarlGray&#x2F;language-incubator&#x2F;blob&#x2F;29755c32...</a>
评论 #31219123 未加载
评论 #31211742 未加载
评论 #31212061 未加载
tsujaminabout 3 years ago
Not sure how helpful it is for your purposes, but I found the usage of Prolog in Windows NT to dynamically build the network stack super fascinating: <a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20040603192757&#x2F;research.microsoft.com&#x2F;research&#x2F;dtg&#x2F;davidhov&#x2F;pap.htm" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20040603192757&#x2F;research.microsof...</a>
rurbanabout 3 years ago
I use it for reverse engineering unknown struct layouts for DWG classes. A field packing problem.<p>I&#x27;m using picat, a better Prolog dialect, and generate the facts automatically from C to generate the field layouts via picat automatically.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;LibreDWG&#x2F;libredwg&#x2F;blob&#x2F;master&#x2F;examples&#x2F;ACAD_EVALUATION_GRAPH.pi" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;LibreDWG&#x2F;libredwg&#x2F;blob&#x2F;master&#x2F;examples&#x2F;AC...</a><p>optimization problems as in compilers are extremely natural in Prolog.
sm001about 3 years ago
I wrote commercial Prolog applications circa 1990 and it is the nicest programming language that I know (I used over 30 in my 50 year career); I recommend the book The Art of Prolog, by Ehud Shapiro. Also the idea that with Prolog, you can easily write programs that write programs (I wrote a few of those) and that it may be feasible to scale up a program to fill in the code to match input and output descriptions, and build possibly unlimited complex logic on top of simpler components, as I think Shapiro was working on this approach in the 1990&#x27;s for the Israeli gov., before the project went under the covers, it seems.
spriorabout 3 years ago
Not a lot of code but a somewhat different use of Prolog than you&#x27;re likely to see elsewhere. I used my fork of a MQTT library for Prolog (<a href="https:&#x2F;&#x2F;github.com&#x2F;sprior&#x2F;swi-mqtt-pack" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sprior&#x2F;swi-mqtt-pack</a>) to implement the central controller for my home automation system. The system responds to MQTT events and then coordinates the appropriate action by sending MQTT messages to other home services. Recent versions of SWI-Prolog also support redis and I&#x27;ve started using that to store device configuration and state between services. The MQTT version is actually a reimplementation of my previous version which used CORBA for inter-service communication.<p>I don&#x27;t distribute the home automation code however it&#x27;s pretty specific to my house. The MQTT library provides some building block examples.<p>You can also see some other comments I&#x27;ve made on HN which describe some other details.
评论 #31213812 未加载
tbenskyabout 3 years ago
The Tau Prolog (<a href="http:&#x2F;&#x2F;tau-prolog.org" rel="nofollow">http:&#x2F;&#x2F;tau-prolog.org</a>) system (written in JS) is used here <a href="https:&#x2F;&#x2F;www.codebymath.com&#x2F;index.php&#x2F;welcome&#x2F;lesson_menu#prolog" rel="nofollow">https:&#x2F;&#x2F;www.codebymath.com&#x2F;index.php&#x2F;welcome&#x2F;lesson_menu#pro...</a> to use Prolog as a way of teaching mathematical concepts.
hyperpallium2about 3 years ago
The first version of erlang was written in prolog. <a href="https:&#x2F;&#x2F;wikipedia.org&#x2F;wiki&#x2F;Erlang_(programming_language)" rel="nofollow">https:&#x2F;&#x2F;wikipedia.org&#x2F;wiki&#x2F;Erlang_(programming_language)</a>
评论 #31212696 未加载
astrangeabout 3 years ago
Mercury (<a href="https:&#x2F;&#x2F;mercurylang.org" rel="nofollow">https:&#x2F;&#x2F;mercurylang.org</a>) is a language descended from Prolog that has some interesting examples. Personally I think it shows a lot more promise than many other languages people get very excited about.
tmalyabout 3 years ago
I used Prolog at my job to fill out complex regulatory forms required in the financial industry. I have a Perl module that queries an Oracle database and constructs the facts database. This is paired with a set of rules to write out the form elements.<p>I have one other Prolog project that is part of a tool. It explains the relationship between potentially related people. It is used in financial surveillance.
zzbn00about 3 years ago
Gerrit&#x27;s prolog rules may be worth a look: <a href="https:&#x2F;&#x2F;gerrit-documentation.storage.googleapis.com&#x2F;Documentation&#x2F;3.4.0&#x2F;prolog-cookbook.html#_prolog_language" rel="nofollow">https:&#x2F;&#x2F;gerrit-documentation.storage.googleapis.com&#x2F;Document...</a> .
carapaceabout 3 years ago
You could look at &quot;PRESS: PRolog Equation Solving System&quot;, &quot;a system for solving symbolic, transcendental, non-differential equations.&quot;<p><pre><code> Journal of Symbolic Computation Volume 7, Issue 1, January 1989, Pages 71-84 &quot;Solving symbolic equations with PRESS&quot; </code></pre> <a href="https:&#x2F;&#x2F;www.sciencedirect.com&#x2F;science&#x2F;article&#x2F;pii&#x2F;S0747717189800070" rel="nofollow">https:&#x2F;&#x2F;www.sciencedirect.com&#x2F;science&#x2F;article&#x2F;pii&#x2F;S074771718...</a><p>Source: <a href="https:&#x2F;&#x2F;github.com&#x2F;maths&#x2F;PRESS" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;maths&#x2F;PRESS</a><p>- - - -<p>BTW, Does anyone know where I can find the source for MIXTUS partial evaluation system?
评论 #31215890 未加载
Vosporosabout 3 years ago
At work we modelled our role-based access control logic in prolog. Once you realise that your authorization is logic programming, you gain access to better tools, more formal ways to think about it, and a treasure trove of literature. :)
评论 #31214600 未加载
h_sakuraiabout 3 years ago
I write Prolog version bulletML in Prolog.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;hsk&#x2F;bulletpl&#x2F;blob&#x2F;master&#x2F;bulletpl&#x2F;1943_rolling_fire.xml" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;hsk&#x2F;bulletpl&#x2F;blob&#x2F;master&#x2F;bulletpl&#x2F;1943_ro...</a><p>It is a movement of the rolling fire of CAPCOM shooting game 1943.<p>Original Bullet ML DSL is XML base, however this version base Edinburgh Prolog format.<p><a href="http:&#x2F;&#x2F;www.asahi-net.or.jp&#x2F;~cs8k-cyu&#x2F;bulletml&#x2F;index_e.html" rel="nofollow">http:&#x2F;&#x2F;www.asahi-net.or.jp&#x2F;~cs8k-cyu&#x2F;bulletml&#x2F;index_e.html</a>
hnbeckabout 3 years ago
At the public funded project <a href="http:&#x2F;&#x2F;vvm-projekt.de" rel="nofollow">http:&#x2F;&#x2F;vvm-projekt.de</a> we are developing methods for verification and validation of autonomous driving. My team developed an analysis method for information flow in urban intersections. The software is implemented in PROLOG (Logtalk). See paper about here (German, will follow in English soon) <a href="https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;2108.00252" rel="nofollow">https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;2108.00252</a> and infos about implementation <a href="https:&#x2F;&#x2F;www.vvm-projekt.de&#x2F;fileadmin&#x2F;user_upload&#x2F;Mid-Term&#x2F;VVM_HZE_S1_P16_20220315_PSMFormalization.pdf" rel="nofollow">https:&#x2F;&#x2F;www.vvm-projekt.de&#x2F;fileadmin&#x2F;user_upload&#x2F;Mid-Term&#x2F;VV...</a> and <a href="https:&#x2F;&#x2F;www.vvm-projekt.de&#x2F;fileadmin&#x2F;user_upload&#x2F;Mid-Term&#x2F;VVM_HZE_S1_P17_20220315_PSMSWArchitectur.pdf" rel="nofollow">https:&#x2F;&#x2F;www.vvm-projekt.de&#x2F;fileadmin&#x2F;user_upload&#x2F;Mid-Term&#x2F;VV...</a> (English). The project will be finished mid 2023<p>Cheers Hans
danieldkabout 3 years ago
Alpino is a natural language parser and generator for Dutch, written largely in (SICStus) Prolog and some C&#x2F;C++:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;rug-compling&#x2F;Alpino" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rug-compling&#x2F;Alpino</a><p>Even in the age of neural parsers, it&#x27;s still one of the most competitive parsers for Dutch.
评论 #31214552 未加载
seth123456about 3 years ago
Not sure it is recommended reading, but maybe to see what else you could do with Prolog besides interpreters, DSLs etc:<p>As part of a knowledge systems course we built a small game in (mostly) Prolog<p><a href="https:&#x2F;&#x2F;github.com&#x2F;tobischo&#x2F;mine-prolog-tba" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tobischo&#x2F;mine-prolog-tba</a>
segmondyabout 3 years ago
<a href="https:&#x2F;&#x2F;www.metalevel.at&#x2F;prolog&#x2F;showcases&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.metalevel.at&#x2F;prolog&#x2F;showcases&#x2F;</a> <a href="https:&#x2F;&#x2F;www.metalevel.at&#x2F;lisprolog&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.metalevel.at&#x2F;lisprolog&#x2F;</a>
Pakoabout 3 years ago
Not sure if you&#x27;d consider this a &quot;complete application&quot; that is bigger than a &quot;Hello-World-esque example&quot; but I&#x27;ve worked on a Discord bot in SWI Prolog[1] for a while with a friend. It was an interesting experience and although a lot of the work (e.g. SWI has a ready-made library for interfacing with WebSockets and sending out HTTPS requests).<p>Some interesting applications of Prolog specifically include using predicates to filter messages by certain criteria (e.g. if it was sent by the bot&#x27;s account or not), being able to hot-reload by invoking the make&#x2F;0 predicate, and homoiconicity to (in theory) easily evaluate random code supplied by a user.<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;prolord-pl&#x2F;prolord" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;prolord-pl&#x2F;prolord</a>
cloogshicerabout 3 years ago
Here&#x27;s an example for a problem that&#x27;s moderately difficult to do recursively, hard to do iteratively, and trivial in Prolog:<p>Given that you have the following coins, 1¢ (i.e. 1 cent or $0.01), 5¢, 10¢, 25¢, 50¢, how many different ways are there to give change for a dollar? For example, one way would be to give 2x50c, another would be to give 100x1c. How many are there total?<p>In most languages this is not super easy to do unless you&#x27;re very comfy with recursion.<p>In Prolog the solution is basically (pseudocode):<p><pre><code> 100 = a*50 + b*25 + c*10 + d*5 + e*1 </code></pre> and Prolog will just figure out all possible combinations for you.<p>The challenge with Prolog as far as I understand is making things fast.
评论 #31216934 未加载
评论 #31215672 未加载
monkeybuttonabout 3 years ago
Make files are prolog programs in drag.
评论 #31214681 未加载
andaiabout 3 years ago
I usually check out the GitHub Trending page for a programming language. Amusingly, the project you linked is the only result for Prolog this month on GitHub.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;trending&#x2F;prolog?since=monthly" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;trending&#x2F;prolog?since=monthly</a>
mtsfz2about 3 years ago
DFS Tools [0] is a Prolog implementation of the Distributional Formal Semantics framework [1].<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;hbrouwer&#x2F;dfs-tools" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;hbrouwer&#x2F;dfs-tools</a> [1] <a href="https:&#x2F;&#x2F;www.sciencedirect.com&#x2F;science&#x2F;article&#x2F;pii&#x2F;S089054012100078X" rel="nofollow">https:&#x2F;&#x2F;www.sciencedirect.com&#x2F;science&#x2F;article&#x2F;pii&#x2F;S089054012...</a>
stunamiabout 3 years ago
Don&#x27;t think you&#x27;d get the codebase for it, but I know this is built in SWI prolog <a href="https:&#x2F;&#x2F;www.securitease.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.securitease.com&#x2F;</a> . Looks like it was presented a decade ago <a href="https:&#x2F;&#x2F;dtai.cs.kuleuven.be&#x2F;CHR&#x2F;files&#x2F;Elston_SecuritEase.pdf" rel="nofollow">https:&#x2F;&#x2F;dtai.cs.kuleuven.be&#x2F;CHR&#x2F;files&#x2F;Elston_SecuritEase.pdf</a>
Beldinabout 3 years ago
I&#x27;ve recently come across &quot;The Eye of Horus&quot;, a paper + associated code base [1] analysing attacking transactions on smart contracts using DataLog (a subset of Prolog). Not all of it is written in DataLog, but the vulnerability analysis is - the core component of the framework.<p>[1] <a href="https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;2101.06204" rel="nofollow">https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;2101.06204</a>
User23about 3 years ago
Norvig’s AI book has a lot of prolog in it.
评论 #31213145 未加载
jb1991about 3 years ago
Lots of neat examples in this book: <a href="https:&#x2F;&#x2F;www.amazon.com&#x2F;Clause-Effect-Programming-Working-Programmer&#x2F;dp&#x2F;3540629718" rel="nofollow">https:&#x2F;&#x2F;www.amazon.com&#x2F;Clause-Effect-Programming-Working-Pro...</a>
sm001about 3 years ago
A great Prolog project would be the implementation of Godel&#x27;s logic language.
Ericson2314about 3 years ago
Not an example of prolog but I wish Ed had time to continue developing <a href="https:&#x2F;&#x2F;github.com&#x2F;ekmett&#x2F;guanxi" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ekmett&#x2F;guanxi</a>.
ThemalSpanabout 3 years ago
I made this demo project a while back, you might find it useful:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;SallySoul&#x2F;regexc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;SallySoul&#x2F;regexc</a>
h_sakuraiabout 3 years ago
eval(I,I):-integer(I).<p>eval(E1+E2,I):- eval(E1,I1),eval(E2,I2), I is I1+I2.<p>eval(E1<i>E2,I):- eval(E1,I1),eval(E2,I2), I is I1</i>I2.<p>:- eval(1<i>2+3</i>4,R),writeln(R),R=14.<p>:- halt.<p>Very simple Operational Semantics.<p>this mean<p>syntax<p>e ::= i | e+e | e * e<p>evaluation rule<p>-------------- (E-Int)<p>i1--&gt;i1<p>e1--&gt;i1 e2--&gt;i2<p>i is i1+i2<p>------------------- (E-Plus)<p>e1+e2 --&gt; i<p>e1--&gt;i1 e2--&gt;i2<p>i is i1<i>i2<p>------------------- (E-Times)<p>e1*e2 --&gt; i</i>
odirootabout 3 years ago
I vaguely remember Maemo on Nokia N900 used Prolog to manage the sound system (notifications, priorities etc).
i_don_t_knowabout 3 years ago
What’s the best way to get started with Prolog on macOS? Implementations, editors, etc?
评论 #31215926 未加载
Parker_Powellabout 3 years ago
Prolog is a programming language that was developed in the 1970s. It is a logic-based programming language, which is pretty different from your typical programming language. Instead of writing functions and then having the computer execute them, Prolog lets you write rules and it will try to deduce the answers to your questions.<p>It&#x27;s a pretty wild concept, and there are tons of cool examples of what Prolog can do. Some examples are:<p>- A solver for Suduko puzzles: <a href="https:&#x2F;&#x2F;rosettacode.org&#x2F;wiki&#x2F;Sudoku#Prolog" rel="nofollow">https:&#x2F;&#x2F;rosettacode.org&#x2F;wiki&#x2F;Sudoku#Prolog</a><p>- A simple game where you guess a person&#x27;s age: <a href="https:&#x2F;&#x2F;rosettacode.org&#x2F;wiki&#x2F;Guess_the_number#Prolog" rel="nofollow">https:&#x2F;&#x2F;rosettacode.org&#x2F;wiki&#x2F;Guess_the_number#Prolog</a><p>- A family tree program: <a href="https:&#x2F;&#x2F;rosettacode.org&#x2F;wiki&#x2F;Family_tree#Prolog" rel="nofollow">https:&#x2F;&#x2F;rosettacode.org&#x2F;wiki&#x2F;Family_tree#Prolog</a>