Canned Dogelog Runtime for Prolog Snippets


The Dogelog runtime is a Prolog system that completely runs inside a browser. It is written in JavaScript for new browsers. We discuss how the Doglog runtime can be canned, so that it runs in old browsers setups. Using canned Dogelog runtime, stackoverflow snippets are made possible.

Module Restrictions

The Dogelog runtime is developed ES6 module style. ES6 modules have some benefit for development of the Dogelog runtime. However, ES6 modules also impose more restrictions on the resulting code.

For example, ES6 modules are fetched via the Cross-Origin Resource Sharing (CORS) protocol, which not only requires a local server for testing, but also imposes by default a Same-Origin-Policy (SOP).

So one might be tempted to do the following:

<script type="module">
    Import .. from "http://www.dogelog.ch/lib/index.js";
    Etc..
</sctipt>

This will result in a CORS error in a modern browser:

Single File

The transpiler offers the bundler predicates bundle_clear/1 and bundle_add/2. By means of these predicates, a canned Dogelog runtime can be put together, stripping ES6 module style. The following files need to be collected:

runtime/machine.js
runtime/special.js
runtime/compile.js       ---+
runtime/loader.js           |
runtime/index.js            +---> canned/dogelog.js
                            |
transpiler/exchange.js   ---+

By the canned distribution of the Dogelog runtime, it is possible to include Prolog code snippets in stack overflow answers. Stack overflow provides a wizard to insert a snippet into an answer. An example was put into the wild at this web address:
http://stackoverflow.com/a/67990574/502187

A screenshot of running the stackoverflow snippet is seen here:

Polyfill Issues

Unfortunately, the canned Dogelog runtime does not yet solve all old browser compatibility problems. We discuss some remaining problems. Old browsers might not offer features from the newest 11th Edition of the ECMAScript standard (ES11) from 2020. Among features used by Dogelog runtime is the JavaScript bigint primitive numbers type.

The Dogelog runtime switches to bigint for integers outside of the range from -94906266 to 94906266. The Dogelog runtime uses also bigint for floats that are integral and in the range from -94906266 to 94906266. The latter is needed so that 1 = 1.0 fails. Therefore, the lack of bigint type affects both Prolog integers and Prolog floats.

For more details see the Dogelog reference manual:
http://github.com/jburse/dogelog-moon/tree/main/manual

Conclusion

The Dogelog runtime is marturing. It has new applications like stackoverflow snippets we didn't even think of, when making the first prototype. To give the Dogelog runtime a platform for discussion, there is now this Facebook group:
http://www.facebook.com/groups/dogelog