ProscriptLS
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
</body>
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" src="my_program.pl"> </script>
-
The 'script' tag with the source as the text content of the 'script' element:
<script type="text/prolog"> my_program :- some_code. </script>
-
Consulting a source file using the proscriptls function:
<body onLoad= "proscriptls( '\'wam_compiler:consult\'([my_program])');"> More HTML </body>
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">
<head>
<title>ProscriptLS Basic</title>
</head>
<body onload="proscriptls_init ();">
<div>
<h2>ProscriptLS Basic</h2>
<p>
The button displays an alert
dialog containing
'Hello World'
</p>
<div id="basic"></div>
</div>
<script type="text/javascript"
src="../dist/proscriptls.js">
</script>
<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),
dom_object_method(Button,
addEventListener(click,
alert('Hello World!'))),
append_dom_node_child(E, Button).
</script>
</body>
</html>
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.