Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Web Programming in SWI Prolog (2019) (monolune.com)
85 points by luu on Feb 21, 2020 | hide | past | favorite | 14 comments


Also check out Anne Ogborn's tutorial "Creating Web Applications in SWI-Prolog" http://www.pathwayslms.com/swipltuts/html/

Following that I made a very simple ("hello world" simple) server that serves Tau Prolog ( http://tau-prolog.org/ ) to the client and establishes a websocket connection between them.

It's here FWIW: https://git.sr.ht/~sforman/yrad-nettles (WARNING: it's not meant for public consumption, I think it might be broken at the moment because I was experimenting with serving prolog scripts like js scripts when I stopped working on it... I'm putting it out here in case you want to try to glean some insight from it. I was looking over it myself just now and I forget a lot about how it's supposed to work, so read it alongside Anne's tutorial, if at all. Cheers! Also, I should mention it depends on a whole different project, an implementation of Joy programming language, to actually do anything, because it's meant to act as a remote shell/UI for that language hosted in a Prolog server. So, yeah... you're gonna want to comment that out.)


While web programming in Prolog has been insightful, I think there are more expedient areas of application for the language.

Prolog is especially underutilized in databases.


This is a database written in Prolog: https://github.com/terminusdb/terminus-server - albeit with a RUST storage engine - prolog's lack of types means there are better storage solutions, but for constraint logic, it's unbeatable.


A statically typed logic language would be ideal for both



Mercury is cool. I translated a simple Prolog program to it once, and it was a head trip. Hard to get my mind around, but also helped me see the connection between functions and relations.


We evaluated the use of Mercury before settling on prolog for terminusDB. Mercury is a great language, but the community and library support is just a bit too small.


Prolog is already a database, why bring in the mess of an external DB. I have used Prolog and ODBC to access a postgres DB. I found it better to just export the data and turn it into a Prolog DB then process my rules than have it run all those logic across the wire.


What about performance?


For Clojure, there is Datomic[0] (a DB with S-expression Datalog) and DataScript[1] (in memory Datalog for browser) which has a fair amount of usage. Also, there's a bitemporal database use Datalog name Crux[2] seems to be quite promising.

[0] https://www.datomic.com/ [1] https://github.com/tonsky/datascript [2] https://opencrux.com/


Learning web Prolog is my current programming side project. My ultimate goal is to create an online board gaming platform, as writing board game rules in Prolog has turned out to be a smooth and pleasant experience :)

Not to mention, SWI Prolog already has http, websockets, rpcs, and pubsub built in, so there isn't really a need to download any external libraries.


What could be good uses of a prolog-based web service? Calendar availability? Scheduling appointments? Issue diagnosis?


It's a turing complete language... so anything you want!


Maybe we should ask what's the real world use of prolog nowadays ?

We already have countless database at dispodispose. Too many shiny tech which can do recommendations.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: