https://github.com/eignnx/thoreaulog
A simple Prolog implementation written in ReasonML.
https://github.com/eignnx/thoreaulog
javascript-library prolog prolog-implementation reasonml
Last synced: 2 months ago
JSON representation
A simple Prolog implementation written in ReasonML.
- Host: GitHub
- URL: https://github.com/eignnx/thoreaulog
- Owner: eignnx
- License: mit
- Created: 2019-05-09T02:30:59.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T21:43:30.000Z (over 2 years ago)
- Last Synced: 2025-01-21T17:35:39.762Z (4 months ago)
- Topics: javascript-library, prolog, prolog-implementation, reasonml
- Language: Reason
- Homepage:
- Size: 571 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-list - thoreaulog
README
# Thoreaulog
A simple Prolog implementation written in ReasonML. Use it in your web applications!## Example
```javascript
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
```