Hi all,
I’d like to create a gui in js for a program written in prolog, to view exclusively on localhost. I think pengines is the right library to use here. Following the documentation, I downloaded pengines from github and was able to run the genealogist gui, which is a good starting point for the thing I’d like to do.
When I start run.pl though, a lot of unnecessary stuff is added: the swish instance, the scratchpad, the documentation, the admin permissions UI etc. Is there a way to strip all the unnecessary parts? Ideally including as few things as possibile other than my prolog, html, and js files.
In other words, what’s a minimal skeleton, without all the bells and whistles?
If you just want Pengines, library(pengines) as distributed with the system is all you need. You do need to setup the HTTP server yourself though (using library(http/http_server) and possibly a little more depending on what you want). Should be a tutorial
Thanks @jan, I think I’ll start removing manually from load.pl, server.pl, etc, all of the parts that I think aren’t needed. In the meantime, could you explain more the “depending on what you want” part? What things are there besides the http/http_server stuff?
I’d start with just Prolog. The minimal example I came up with is this (actually, it adds HTTP CORS support which you probably need, but is not always required).
101 ?- server(5000).
% Started server at http://localhost:5000/
true.
102 ?- pengine_rpc('http://localhost:5000', member(X, [a,b,c])).
X = a ;
X = b ;
X = c.
to make an otherwise normal http server pengine-enabled? that’s amazing!
And I’m also amazed that the pengine automatically sees the other predicates I define in that file. That’s a start.
Now a question: I’m creating an html file (it’s not strictly necessary for it to be served by prolog).
But the example one contained the line:
<script src="/pengine/pengines.js"></script>
and I can’t find a pengines.js file in the example repo! Is there some magic that makes that available in the example?
Since the title of the topic is Minimal pengine example and not Minimal pengine example with HTML front using JavaScript others reading this topic might find this post from the days when the forum was in Google Groups useful:
Thanks @jan, I can indeed use https://pengines.swi-prolog.org/pengine/pengines.js or download it and call it from my local directory. My question was that the genealogist example seems to be using it locally, but there’s no local pengines.js file in the pengines repo, so I wondered how that worked.
It is the same server serving pengines.js, so you can use a relative URL. If you can, that is a better idea as it makes it easier to move the server around. Also in your case it might be a good idea to have your HTML files served through the same (Prolog) server.
here https://github.com/hnbeck/ecblackjack is a small Web-Based game I wrote some month before. It is not that simple, but also not complex. Surly not the best code It uses TauProlog and Pengines, so you may look at it for some ideas what can be done.