HTML Page

This is the main page of the sandbox example with the corresponding HTML elements and using the Dogelog player. To use the Dogelog player in our example, we first import those functions or variables we need. This is done by the following JavaScript statement:

    import {init, clear, set_output, consult, show} from "./lib/index.js";

The import will also load all the other JavaScript files that are subsequently imported by the File "index". We do not have to list everything in the main page. We now have to define an output callback and initialize the Dogelog interpreter once:

    init();

function log(buf) {
document.getElementById("demo").innerText += buf;
document.getElementById("demo").innerHTML += "<br>";
}

Finally there is a function main which gets called every time the button is pressed. This func-tion will first reset the output box and also remove all user clauses from the Prolog database via the function clear(). It will then consult the text from the input box:

    function main() {
document.getElementById("demo").innerHTML = "";
clear();
set_output(log);
let text=document.getElementById("text").value;
consult(text);
}

document.getElementById("launch").addEventListener("click", main);

The error handling is quite primitive. The function consult() doesn't need some special clean-up, it does all the clean-up itself. All we do is show the error term. The function show() will use the registered output callback and write the error term canonical.

Kommentare