scryer
TypeScript icon, indicating that this package has built-in type declarations

0.5.1 • Public • Published

scryer

This is a Typescript package that embeds Scryer Prolog.

Experimental, API will change. Currently it's (roughly) based on trealla-js's API.

npm install scryer
import { init, Prolog } from "scryer";

await init();

const pl = new Prolog();
const query = pl.query("X = 1 ; X = 2.");
for (const answer of query) {
	console.log(answer.bindings);
}

For browsers, you can use esm.sh or other CDNs to import it directly:

<script type="module">
	import { init, Prolog } from "https://esm.sh/scryer"; // ideally add version info to the URL, e.g. scryer@0.1.0
	await init();
	// query stuff
</script>

Usage

Binding variables

const answer = pl.queryOnce("X is Y * 2.", { bind: { Y: 21 } });
console.log(answer.bindings); // { X: 42, Y: 21 }

Template strings

The prolog string template literal is an easy way to escape terms. Each ${value} will be interpreted as a Prolog term.

import { prolog, Variable } from "scryer";
const answer = pl.queryOnce(
	prolog`atom_chars(${new Variable("X")}, ${"Hello!"}).`,
);
console.log(answer.bindings); // { X: Atom('Hello!') }

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.5.13latest

Version History

VersionDownloads (Last 7 Days)Published
0.5.13
0.5.02
0.4.11
0.4.01
0.3.01
0.2.11
0.2.01
0.1.31
0.1.21
0.1.11
0.1.01
0.0.21
0.0.11

Package Sidebar

Install

npm i scryer

Weekly Downloads

16

Version

0.5.1

License

BSD-3-Clause

Unpacked Size

6.32 MB

Total Files

7

Last publish

Collaborators

  • guregu