Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swipl-wasm

Package Overview
Dependencies
Maintainers
2
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swipl-wasm

SWI-Prolog WebAssembly build as a NPM package. Please see this page for ongoing progress and information: <https://swi-prolog.discourse.group/t/swi-prolog-in-the-browser-using-wasm/5650>

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
490
decreased by-54.67%
Maintainers
2
Weekly downloads
 
Created
Source

swipl-wasm

SWI-Prolog WebAssembly build as a NPM package. Please see this page for ongoing progress and information: https://swi-prolog.discourse.group/t/swi-prolog-in-the-browser-using-wasm/5650

Usage

In browser:

<div id="solution"></div>
<script src="/dist/swipl/swipl-web.js"></script>
<script>
  (async () => {
    const swipl = await SWIPL({
      noInitialRun: true,
      arguments: ["-q"],
      locateFile: (url) => {
        if (url === "swipl-web.data") {
          return "/dist/swipl/swipl-web.data";
        } else if (url === "swipl-web.wasm") {
          return "/dist/swipl/swipl-web.wasm";
        }
        return url;
      },
    });
    const query = "member(X, [a, b, c]).";
    const solutionElement = document.getElementById("solution");
    // See https://swi-prolog.discourse.group/t/swi-prolog-in-the-browser-using-wasm/5650/1
    const firstSolution = swipl.prolog.query(query).once().X;
    solutionElement.textContent = firstSolution;
  })();
</script>

You can run this example by executing npm run test:serve-http and visiting http://localhost:8080/examples/browser.html.

In Nodejs:

// This helps to find the correct locations of the
// .data and .wasm files.
const swiplModuleLocation = require.resolve("swipl-wasm/swipl");
const swipl = await SWIPL({
  noInitialRun: true,
  arguments: ["-q"],
  locateFile: (url) => {
    // These are common with the web version.
    if (url === "swipl-web.data") {
      return path.join(path.dirname(swiplModuleLocation), "swipl-web.data");
    } else if (url === "swipl-web.wasm") {
      return path.join(path.dirname(swiplModuleLocation), "swipl-web.wasm");
    }
    return url;
  },
});
// See https://swi-prolog.discourse.group/t/swi-prolog-in-the-browser-using-wasm/5650/1
console.log(swipl.prolog.query("member(X, [a, b, c]).").once().X);

You can run this example with node examples/run-on-node.js.

Build

The package can be built using npm or yarn. Please use yarn to add new dependencies and update yarn.lock file. SWI-Prolog WebAssembly version is currently built inside Docker with Emscripten.

TODO

License

Same as SWI-Prolog license, BSD simplified: https://github.com/SWI-Prolog/swipl-devel/blob/master/LICENSE

FAQs

Package last updated on 21 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc