How to make a SWI-Prolog compiler online?

Hello everybody.
It seems really very hard to install on a website a Prolog compiler where visitors can test some programs. I have downloaded pengines and tested it locally, but I met quickly sandbox limitations without understanding of getting rid off theses limitations.
By contrast, I had no problem to publish fCube.pl here:
https://rextester.com/SEOO25214
which works smoothly in this website, but not in SWISH.
I would be happy to get for my personal website something that works like in this example. I guess that it is not so complicated, but I need help.
Best wishes ,
Jo.

I uploaded the code and example to SWISH -- SWI-Prolog for SHaring. It raised an error on tab/1 where the SWISH emulation didn’t accept an expression as the built-in one does. Fixed it first by using is/2 before calling tab/1. Now the example seems to work. Updated SWISH to make the behavior of tab/1 compatible after which the code runs unmodified.

That said, the system performs a lot of one-character write/1 calls that result in a web server interaction each and thus it writes as computers in very old movies did :slight_smile: Just needs green on black :slight_smile: You can fix that by using with_output_to(string(S), Goal) and then write(S) to send the output as one object. You could also use the HTML output facilities to both avoid most of this overhead and get pretty looking output.

Still, SWISH is not the same as an online Prolog in a terminal. It adds things, especially when it comes to presenting results and looses, mostly due to lack of persistent state and sandbox limitations. For fCube it looks like you can build a nice looking web application in SWISH (see SWISH -- SWI-Prolog for SHaring)

There are enough systems around that package arbitrary systems as a remote service. Most will run the system in an OS sandbox I guess and connect the I/O.

1 Like

Thanks Jan, for having replied to Jan and also for having published fCube on SWISH .

Have a good evening !

Best wishes,

Jo.

If you don’t care about security and want to be able to execute arbitrary queries, there’s a server here (and a javascript client): GitHub - kamahen/swipl-server-js-client: Sample SWI-Prolog server with JavaScript client

1 Like

Thanks Peter ! It is indeed very interesting for me and I will look at it very soon. I will inform you.

All the best,

Jo.

Hello Peter,
I had tested your simpleserver, and indeed it works perfectly with the examples of command that you give. But this is almost the only thing that I am able to do with it. I stay unable to load and consult a file (to put it in static/ directory changes nothing), and I have written in simple_client.html a text area with leanseq.pl like in this webpage, but unfortunately, to the query provable(((a & b) => a), Proof). I get :

Success: 	error
Error: 	error(syntax_error(operator_expected),string("provable(((a & b) => a), Proof). ",12))

I am lost… :frowning:

The easiest way of running your code is to put it into a file (e.g. leanseq.pl) and then simply typing [leanseq]. into the REPL prompt for the server, like this:

$ swipl simple_server.pl --port=9999 --staticdir=static
% static dir: static
% Started server at http://localhost:9999/
% Starting REPL ...
?- [leanseq].

After I did this, I tried your query on the browser and got the following:

Query: provable(((a & b) => a), Proof).
(after) provable((a&b=>a),rcond([]>[(a&b=>a)],land([(a&b)]>[a],ax([a,b]>[a],a))))
Success: true
Error: ``
Vars: Proof rcond([]>[(a&b=>a)],land([(a&b)]>[a],ax([a,b]>[a],a)))
Printed:

If you want to be able to execute an arbitrary program (as opposed to a simple query), then you’ll need to enhance the javascript client to take a program and consult it. You’ll also need to figure out a way of keeping separate “engines” for the various users, etc., etc. and pretty soon you’ll have something like SWISH. :wink:

(The static directory is for serving static HTML pages, images, and Javascript code; e.g., simple_client.html is here, so that the server can send it to the browser – on the server, this is done by the http_handler(static(.),...) directive, and an HTTP GET request results in the contents of static/index.html (this is done with a 301 redirect). You can see how this happens if you use curl on localhost:9999 … the resulting page contains a <script> tag that loads simple_client.js, which is also in the static directory.)

Many thanks Peter. I made the error to try to load leanseq.pl via the query area. It works smoothly, and the output appears as quick as in emacs, maybe more.
I will try now to use your work online, in my personal blog.
Thanks again and happy december 31 ! :wink:

Glad to have been of help. If you notice anything that needs improving in my code, please send me a change (I’m not very good at git, so the best way would be a PR; if you send me a diff, I don’t know how to incorporate it while crediting you, except in the commit comment).

My goal is now to use your tool in adapting it for my blog which runs on https.

I have to understand how to run SWI-Prolog daemon , etc. I do not doubt that for experts like Jan and you, it is a piece of cake, but I do not want to abuse of your kindness and of your time. I will try, and if I am lost again, if I am in a dead end, I will warn you.
Best wishes ,
Jo.

1 Like

https://swi-prolog.discourse.group/t/how-to-use-of-upcase-atom-2-to-get-uppercase-letters-in-an-output/4693/63?u=joseph-vidal-rosset

Discourse has a feature called Onebox where a standalone URL with no preceding spaces on a line by itself will be converted into a Onebox, E.g.

:slightly_smiling_face: