thoreaulog

0.1.10 • Public • Published

Thoreaulog

A simple Prolog implementation written in ReasonML. Use it in your web applications!

Example

const {
    KnowledgeBase,
    Query,
    Term,
} = require("thoreaulog");

const kb = new KnowledgeBase();
kb.addFact("likes", ["darcy", "carrie"]);
kb.addFact("likes", ["carrie", "darcy"]);

const likes = (a, b) => Query.Term(Term.Pred("likes", [a, b]));
const [X, Y] = [Term.Var("X"), Term.Var("Y")];

const q = Query.And([
    likes(X, Y), likes(Y, X)
]);

const ans = [
    {
        "X": Term.Atom("carrie"),
        "Y": Term.Atom("darcy"),
    },
    {
        "X": Term.Atom("darcy"),
        "Y": Term.Atom("carrie"),
    },
];

// Extract answers incrementally...
kb.query(q);
const actual = [kb.answer(), kb.answer()];
expect(actual).toEqual(ans);

// ...or all at once.
kb.query(q);
expect(kb.allAnswers()).toEqual(ans);

Build

npm run build

Run Tests

Requires jest is installed on your system ($ which jest should return something).

npm test

Readme

Keywords

Package Sidebar

Install

npm i thoreaulog

Weekly Downloads

1

Version

0.1.10

License

MIT

Unpacked Size

37.7 kB

Total Files

19

Last publish

Collaborators

  • eignnx