Help. invoke a swi-prolog program within an html page

Help. invoke a swi-prolog program within an html page

Post by Gustavo Ro » Thu, 13 Jan 2005 07:48:23


Can I invoke a SWI-Prolog program within an HTML program?
If so, how can I pass input to the program and take
output from it?

Your help will be greatly appreciated.

Help. invoke a swi-prolog program within an html page

Post by Simon A. C » Sun, 16 Jan 2005 10:55:01

SWI Prolog has an interface to Java, so there's a few possibilities. If you
are in a position to run code on the web server, you could write a little
server program to listen to a port. Then your web page could connect to that
directly. I can let you have some code that uses Java Server Pages to
communicate with a simple server and display the results of a query, bit it
probably won't be much use unless you are comfortable with server side Java,




Help. invoke a swi-prolog program within an html page

Post by Norbert E. » Tue, 01 Feb 2005 23:15:06

In article < XXXX@XXXXX.COM >,

Have a look at the Pillow Web Programming Library

where it says

The PiLLoW library ("Programming in Logic Languages on the Web") is a
public domain Internet/WWW programming library for Logic Programming
Systems which simplifies the process of writing applications for such
environment. The library provides facilities for generating HTML or XML
structured documents by handling them as Herbrand terms, producing HTML
forms, writing form handlers, processing HTML templates, accessing and
parsing WWW documents (either HTML or XML), accessing code posted at
HTTP addresses, etc.

Help. invoke a swi-prolog program within an html page

Post by Jan Wielem » Wed, 02 Feb 2005 01:45:00

Pillow is one way. SWI-Prolog itself comes with libraries too. Only,
the question is much underspecified. First of all, I don't think you
can speak about `An HTML program'. That would imply it is a programming
language. Its not even Turing complete. What does invoke a (SWI-)Prolog
program from HTML mean? In my reading javascript and other client-side
embedded code could be called `invoking XYZ'. I do not know whether
Pillow provides server-side embedded Prolog (like PHP for example).
I once wrote that (it still runs the SWI-Prolog application DB), but
never documented it.

Things that can be done is to use Prolog as a CGI scripting language.
There is nothing special here. To make it easy there is a library for
fetching CGI form data (see package clib). You can also server the
pages directly from Prolog using the HTTP package. This also contains
a library `handling them as Herbrand terms': I'm still
not sure this is ideal. From a software design point of view it is
the way to go, I guess. Especially novices prefer using format (or
even write) though and it takes a lot of effort to convince them

Cheers --- Jan

Help. invoke a swi-prolog program within an html page

Post by Nick Wed » Sun, 13 Feb 2005 01:42:23

In message < XXXX@XXXXX.COM >, Jan Wielemaker
< XXXX@XXXXX.COM > writes

I am not trying to guess what the OP wanted, but I know what I would
like. I'll try to specify it.

I have a web page
( ,
not that it matters) which is written in php, and uses SQL to act as a
front end to a database. It works, but I find it a pain updating and
maintaining it. This is not because there's anything wrong with php or
SQL, it's just they (and particularly SQL) are new to me and I am not
finding it easy to get to grips with them.

What I would like is to keep these data in Prolog instead. I learned
Prolog decades ago, and feel comfortable with it.

I know that a database is designed for keeping data in, and it can cope
with one user updating it while another accesses it, and it has in-built
integrity checking and indexing and stuff. And Prolog is not so good at
these things. But I don't need any of that. This is a small database
with very light usage. What I want is to be able to update it by typing
in a few more Prolog clauses, and uploading the Prolog file. I have
access to an ISP (Pair) who let me run binaries on their server. So
what I want is some Prolog interpreter that I can run on their server,
and a way of calling it from inside a web page, like I call SQL.

Yes, I _know_ the right answer is "pull yourself together and go on an
SQL course". But I would like to see a Prolog solution.


Help. invoke a swi-prolog program within an html page

Post by Jan Wielem » Sun, 13 Feb 2005 19:27:58

Can be done quite easily but, unless the data is small, you need a
permanently running Prolog. That can maintain the database in core
and write a transaction log to a file, so you can replay that in case
you need to shutdown Prolog. Now you need to connect it. One way is
to make Prolog do the HTTP service itself (and simply do a redirect to
the right port from the main page). Another is to create a PHP
backend that will contact the Prolog server, just like the SQL one.
Many things in between can be imagined.

For something simple that might be the best way :-) Makes you learn
something new. For example that Prolog standardisation is excelent
if compared to SQL :-)

Cheers --- Jan