Embedding a Prolog-like logic programming language in JavasScript and TypeScript.
npm install logic-dbEmbedding a Prolog-like logic programming language in JavasScript and TypeScript.
- Combining logic programming and database management.
- Can declare relations between JSON documents.
- Well typed relation in TypeScript.
- Practical and simple API.
`` bash`
npm i logic-db
` typescript
import Logic, { v, ne, ty } from "logic-db"
// NOTE Drinking Pairs -- example from "Clause and Effect"
const drinks = new Logic.Table({
name: "drinks",
schema: ty.object({
person: ty.string(),
alcohol: ty.string(),
}),
})
drinks.i({ person: "john", alcohol: "martini" })
drinks.i({ person: "mary", alcohol: "gin" })
drinks.i({ person: "susan", alcohol: "vodka" })
drinks.i({ person: "john", alcohol: "gin" })
drinks.i({ person: "fred", alcohol: "gin" })
drinks.i({ person: "fred", alcohol: "vodka" })
const pair = new Logic.Table({
name: "pair",
schema: ty.object({
p1: ty.string(),
p2: ty.string(),
alcohol: ty.string(),
}),
})
pair.i({ p1: vp1, p2: vp2, alcohol: valcohol }, (v) => [p1
drinks.o({ person: v, alcohol: valcohol }),p2
drinks.o({ person: v, alcohol: valcohol }),p1
ne(v, vp2),
])
console.log(pair.query({ p1: vx, p2: "mary", alcohol: "gin" }))x
console.log(pair.query({ p1: v, p2: vy, alcohol: "gin" }))x
console.log(pair.query({ p1: v, p2: vy, alcohol: valcohol }))``
Clause and Effect
- By William F. Clocksin.
Structure and Interpretation of Computer Programs (SICP)
- By Harold Abelson and Gerald Jay Sussman.
- It has one section about logic programming:
- sarabander-sicp
- official
The Power of Prolog
- An excellent modern teaching of Prolog, by Markus Triska.
TODO
> Be polite, do not bring negative emotion to others.
- TODO.md
- STYLE-GUIDE.md
- CODE-OF-CONDUCT.md
- When contributing, add yourself to AUTHORS
- GPLv3