Rich UI for Prolog

Hello,
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.

2 Likes

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.

2 Likes

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?

1 Like

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

Nicos Angelopoulos

https://stoics.org.uk/~nicos

2 Likes

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
https://stoics.org.uk/~nicos

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 https://www.electronjs.org 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

this was something that was on my mind for a while. I think it could really be interesting to see if one could generate htmx with prolog to have something quite reactive

I have a full implementation of Essence (semat.org) in SWIPL Prolog. I use a HTML Bootstrap front end, with JSON Web services Prolog Backend. AXIOS is used by GUI javascript to call web services. The prolog backend serves the web pages and the HTTP APIs. It uses the prolog persistence for DB. I have found it extremely easy to modify. I cannot believe how easy it is to modify compared to Spring/Java world I normally work in. I have an architecture diagram, and Powerpoint presentation showing the front end, if these can be shared somehow here ? I am hoping to open source this for research. I can demo if you want to see.

5 Likes

I would love to see a demo

1 Like

I will arrange a demo

1 Like

I wonder if this could be taken any further and achieve an Elm like behavior where UI interactions can be reversed/undone, given Prolog’s predicates’ multi-directional behavior…

I don’t think that Prolog’s backtracking is the way to add “undo” … the easiest (and best?) way that I know is to have a journal of actions;(*) the current state of the UI can be created by re-playing the journal; and an “undo” re-plays it in reverse.

(*) My recollection is that Java Swing has something like this, with each event being put into a queue - this provides a kind of loosely-coupled MVC style of UI that avoids the need for complicated threads in order to get responsiveness.