Prolog Server Pages
⏹ Server-Side Prolog Scripting
Prolog Server Pages (PSP) is a server-side scripting language based on Prolog. In the current implementation is released for usage under Windows 10/8/7/Vista/XP only. PSP is added to the handler mappings of the Microsoft Internet Information Services (IIS) webserver as a Common Gateway Interface (CGI) module. Support for operating systems other than Windows and webservers other than IIS as well as utilization of FastCGI instead of CGI are all planned enhancements for future releases. Nonetheless, the software can be recompiled using the provided source code at needs. Support can be asked through the project website (http://www.prologwebservices.com/).
⏹ Simple and elegant Prolog-HTML integration
The current implementation provides a unique attribute named
that is valid for all HTML tags (Notice that PSP removes prolog attributes before sending output,
thus the documents always remain HTML-valid). The underlying execution model is
that the prolog goal contained as attribute to an HTML tag enwraps the HTML
code contained within the tag and backtracks successively.
In addition to readability, another advantage is the
incentive to put long pieces of Prolog code into separate files, which also
facilitates code re-use. Let us assume, for example, that a standard Prolog
database.pl contains the following
:- dynamic p/1, q/1.
Now consider the following PSP page:
<body psp:prolog="ensure_loaded( database.pl )">
Now X is <b psp:prolog="write(X)"> </b><br>
<span style="text-decoration: underline;" psp:prolog="q(X)">
Do something when X=c here!<br>
The resulting code is more compact, elegant and easy to manage than chunk-based code. The generated output will be:
Now X is b
Now X is c
Do something when X=c here!
Now X is d
The above example also illustrated the fact that standard
HTML tag attributes are untouched by the PSP parser. One limitation of the
present syntax scheme is that sometimes it is necessary to use seemingly
redundant HTML tags to incorporate the required prolog code, as we did above
span. However, as a side-effect this
requirement helps maintaining appropriate context for the Prolog code.
Importantly, variables are local to the HTML tag where Prolog code appears.
In order to perform actions before HTTP headers are sent,
PSP requires that Prolog code is contained in the
tag. Below is an example to implement server-side redirection:
<html xmlns:psp="http://www.prologwebservices.org/psp" psp:prolog="
http_redirect(moved, 'http://www.prologwebservices.com/', Request)
Note that having a
attribute in the
<html> tag is also the
only way to have variables that are global to the entire page. The SWI Prolog
HTTP library provides several predicates that can be used to inspect and
manipulate HTTP headers.