0.1.10 • Published 5 years ago

thoreaulog v0.1.10

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

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
0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago