See also:
The distribution comes with examples
Under swiplexe_8.3.22/lib/swipl/doc/packages/examples/pengines
we find:
pengines/ ├── client.pl ├── server.pl └── web ├── chunking.html ├── debugging.html ├── hack.html ├── index.html ├── input_output.html ├── pengine.html ├── queen.png ├── queens.html ├── simple.html └── update-jquery
Plus the file pengines.js
in
swiplexe_8.3.22/lib/swipl/library/http/web/js/pengines.js
The server code in server.pl
is very simple:
:- module(pengine_server, [ server/1 % +Port ]). :- use_module(library(http/thread_httpd)). :- use_module(library(http/http_dispatch)). :- use_module(library(http/http_server_files)). :- use_module(library(http/http_files)). :- use_module(library(pengines)). :- use_module(pengine_sandbox:library(pengines)). :- http_handler(/, http_reply_from_files(web, []), [prefix]). server(Port) :- http_server(http_dispatch, [port(Port)]).
So what happens:
- The code in
server.pl
registers a http handler using http_handler/3 (called as a directive) - The http handler will call http_reply_from_files/3 on any path (i.e. on path
/
and any subpath thereof) and it will serve any files in theweb
directory, so you can ask forchunking.html
for example. chunking.html
, executed in a web browser:- loads
/js/pengines.js
- defines Prolog code in a script block declared as having type
text/x-prolog
- creates a "Pengine Proxy" in the browser which pushes the Prolog code to the Pengine server and starts it
- allows to retrieve more "answer chunks" by wiring a "Next" button to Javascript calls to
pengine.next()
.
- loads
See also:
More on Communicating FSMs here:
https://en.wikipedia.org/wiki/Communicating_finite-state_machine
The (paywalled) paper from 1983 by Brand and Zafiropulo is here: