The WASM build ships with the Prolog library and thus Prolog
libraries can be loaded as normal using use_module/1,
etc., for example, we can include the lists
library using
this directive. Note that the normal autoloading of library
code works in the WASM version.
:- use_module(library(lists)).
When Prolog is in asynchronous mode, i.e., called through
Prolog.forEach(),
we can also load code from a URL. For example, we can load the CHAT80
demo program directly from
GitHub
using238The
c
continues the quoted atom from the next line after removing leading
white space.
\
?- consult('https://raw.githubusercontent.com/JanWielemaker/\c chat80/master/prolog/chat80.pl').
Larger files can be loaded as .qlf
files. See section
4.3.3 and
qcompile/2.
Notably we can create a single qlf file from an application using the include(user)
option. Below we create a .qlf
file from CHAT80.
The resulting chat80.qlf
can be loaded from a URL using consult/1
as above.
?- qcompile('chat80.pl', [include(user)]).
There are three ways to load Prolog code from JavaScript: (1) loading
from a string, (2) loading from <script>
elements and
(3) loading from URL. Note that all the loading methods return a Promise
that is resolved when loading the data is completed.
/string/1
, /string/2
, ... .type
set to text/prolog
. The file reference for the loaded
script is /script/Id
, where Id is derived from
(1) the
id
of the script, (2) the name
of the script
or (3) being the nth Prolog script in the document. When resolved, the
promise returns an array with the names of the loaded scripts.library(lists)
or a URL. The
sources are downloaded and processed sequentially. This uses
Prolog.forEach()
calling load_files/1.
The returned
Promise
returns 1 on success.