Did you know ... Search Documentation:
Title for wiki('Annotation--annotation')
0 upvotes 0 0 downvotes
Picture of user LogicalCaptain.

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 the web directory, so you can ask for chunking.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().

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:

https://dl.acm.org/doi/10.1145/322374.322380