Prolog for the Web

The ProscriptLS language is a version of Prolog that runs in web browsers. It aspires to be a superset of ISO Prolog that is a complete alternative to Javascript for implementing web sites. (This site is implemented using ProscriptLS instead of Javascript.)

It supports interaction with the HTML Document Object Model (DOM) through builtin predicates. There is a full source-level Prolog debugger based on the Byrd Box Model available through an in-client command-line ProscriptLS interpreter.

The implementation uses a runtime engine that interprets byte codes. This engine is implemented in Javascript and is a version of the Warren Abstract Machine (WAM).

The ProscriptLS SDK associated with each release contains all of the files needed to develop a ProscriptLS web site.

Running ProscriptLS

ProscriptLS is started by the proscriptls_init function (implemented in the proscriptls.js library). This function is typically invoked once per load of the web page in an onload handler for the 'body' element:

<body onload=
        "proscriptls_init ();">
Body stuff

Compiling ProscriptLS programs in the web client

The proscriptls_init function supports compilation of ProscriptLS programs in the client using the 'script' tag with the 'type' attribute of 'text/prolog' or using the ProscriptLS 'consult/1' predicate.

Compilation Examples

  • The 'script' tag with the source being a file specified using the 'src' attribute:
    <script type="text/prolog"
  • The 'script' tag with the source as the text content of the 'script' element:
    <script type="text/prolog">
    my_program :-
  • Consulting a source file using the proscriptls function:
    <body onLoad= "proscriptls( '\'wam_compiler:consult\'([my_program])');">
    More HTML

Basic Example

The following HTML source is a basic example showing the use of a ProscriptLS program to create a 'click me' button that when clicked displays a 'Hello World' alert dialog.

<html lang="en">
    <title>ProscriptLS Basic</title>
<body onload="proscriptls_init ();">
    <h2>ProscriptLS Basic</h2>
        The button displays an alert
        dialog containing
        'Hello World'
    <div id="basic"></div>
<script type="text/javascript"
<script type="text/prolog">
:- initialization(setup_button).

setup_button :-
    dom_element_attribute_value(E, id, basic),
    create_dom_element('BUTTON', Button),
    create_dom_text_node("Click Me", NewContent),
    append_dom_node_child(Button, NewContent),
            alert('Hello World!'))),
    append_dom_node_child(E, Button).
The ':- initialization(setup_button).' statement in the Prolog source is a Prolog compiler directive that causes the wam_compiler to evaluate 'setup_button' after completing the compilation of the Prolog source in that 'script' element.