0.5.1 • Published 10 months ago

scryer v0.5.1

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
10 months ago

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!') }
0.5.1

10 months ago

0.5.0

10 months ago

0.4.1

10 months ago

0.4.0

10 months ago

0.3.0

10 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago

0.0.2

11 months ago

0.0.1

11 months ago