Rich UI for Prolog

have anyone implemented applications with rich UI and Prolog-backed implementation behind it?
I’d like to hear about your approaches and experiences. For now I’ve settled for combination of browser + Prolog http server for backend. Browser can be replaced by any technology capable of making http requests (like game engine, for example). It’s workable for sure, but has some drawbacks. Maybe there is a better solution.

These days, the browser is typically my favorite. But yes, it isn’t ideal for everything. It should open (never tried) an easy way to move to GitHub - electron/electron: :electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS.

The old local option is to use the bundled xpce graphics library. Not really recommended. It is old and lacking a lot of features you’d expect these days (scaling graphics, alpha channel, …). It is mostly maintained to keep the development tools alive (so it won’t die quickly).

A new alternative might be to use the new Janus interface to Python and build on one of Python’s UI libraries.

Another option is using JPL (Java). Then there are several libraries floating around to do things such as binding to OpenGL.

I think my first bets would be electron or Janus/Python, though I never tried one of these.


I wanted to mention that there’s a framework called htmx that can make using the browser interface better. As htmx requests HTML fragments, you can configure your Prolog code to return a small HTML fragment for each component of the interface, allowing you to build advanced websites without touching any JavaScript.

I’m very happy with using a pengine from a js frontend. The code is extremely short, and for personal projects that I don’t have to publish, I compute in prolog directly the js codepatch that changes the frontend. In this way I don’t have to marshall data to and from js, I get a universal interface on the js side (because I just eval the answers from the pengine, for all my questions).

If you are interested I can share code snippets, I have never been happier with a prolog setup.

1 Like

Yeah, it would be very nice of you. I’ve never really touched pengines, just have implemented vanilla HTTP server. Can you clarify: is it serverless solution (prolog running inside browser as WASM code) or alternative way of implementing server?

It would be nice to have a UI section on the SWI web-page.

Nicos Angelopoulos

1 Like

I settled on sveltekit for frontend, prolog
very good for backend. If I used prologue for the frontend I wouldn’t be able to make a beautiful interface

Sounds very interesting. Would you have a minimal working example/tutorial you could make public ?

Nicos Angelopoulos

I used examples from the documentation and github, preparing examples takes a lot of time, maybe in the future I would do this.

Combination of HTML + prolog is good enought, but deployment and configuration management becomes more difficult. I’d like to have “one-in-all” package launched as classic desktop application and displaying UI without browser interface.

Have you looked at PWA applications?

Looked in up after you’ve mentioned it.
It solves the problem with UI and getting rid of browser UI scaffold. Second problem persists - how to package web front end and prolog backend into single entity which runs as a whole.

I think was invented for that purpose? I have never used it. I’d assume you can embed SWI-Prolog into it. I don’t know how it is supposed to communicate and whether or not significant coding is required to make that happen. Possibly the Python Janus interface can help, at least to investigate this route?

What does it mean to pack? I’ll just stick with make for now. You can build a deb or rpm package or use ansible or docker, swi -prolog does not have a package manager like erlang or closure