Whoa! What is swipl.js? Is it what it appears to be?

In looking at the SWI-Prolog devel issues saw

That lead to

So is this what I think it is, a way to use SWI-Prolog from JavaScript?

Are there any caveats or things one should be aware of when using?

1 Like
Consult external files
Load code from external files. You might have to set the working directory if you want to use relative paths.

swipl.call('working_directory(_, prolog)');
swipl.call('consult(mycode)');

Based on this, I expect this is for server-side use.

The linked issue is about swipl.js which is a WebAssembly build of SWI-Prolog. It can run in browsers and in node.js. It consists of a wasm binary and JavaScript-based glue code.

On the other hand, swipl package on npm is a normal x86 binary version of SWI-Prolog running in the same process as node.js. The package consists of C++ based binding code to node.js native interface. It does not run in browsers.

The main differences:

  • swipl package allows spawning threads in Prolog while swipl.js does not
  • swipl package shares memory with the node.js process while swipl.js is in wasm sandbox
  • swipl package can easily use native IO (networking, memory mapped files, etc) while swipl.js cant
  • swipl package can use all extensions (odbc, etc) while swipl.js cant
  • swipl package is 64 bit on 64 bit machines with all the benefits it has while swipl.js is 32 bit
  • swipl package cannot run on browsers but swipl.js can

I guess that swipl.js could have a npm package too. It would likely make its usage a lot easier as it can skip the confusing build step and ship the wasm binary built centrally.

4 Likes

Is there some npm package which has WASM already prebuilt.
So that I have only to do:

npm i <the package I am looking for>

There is an other package, but it seems not to have swipl.js included:

https://www.npmjs.com/package/swipl-wasm

And building from swi-prolog devel is clumsy. It has million undocumented
or documented and hard to decipher pre-requesites, eating a lot of time.