-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_example.ts
More file actions
38 lines (35 loc) · 1.14 KB
/
_example.ts
File metadata and controls
38 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { concrete } from "./concrete.ts";
import { fact } from "./fact.ts";
import { follows } from "./follows.ts";
import { from } from "./from.ts";
import { generateDB } from "./generateDB.ts";
import { symbol } from "./symbol.ts";
import { and } from "./and.ts";
import { concretize } from "./concretize/concretize.ts";
import { Logic } from "./types.ts";
const db = generateDB(() => {
fact("father", concrete("sergey"), concrete("andrew"));
fact("father", concrete("sergey"), concrete("bohdan"));
fact("notequal", symbol("A"), symbol("B"), (db, a, b) => {
if (a.kind !== Logic.Concrete) return [];
if (b.kind !== Logic.Concrete) return [];
return a.value !== b.value ? [[a.value, b.value]] : [];
});
from(
fact("father", symbol("X"), symbol("Y")),
and,
fact("father", symbol("X"), symbol("Z")),
and,
fact("notequal", symbol("Y"), symbol("Z")),
);
follows(
fact("sibling", symbol("Y"), symbol("Z")),
);
});
const request = concretize(
db,
fact("sibling", symbol("A"), symbol("B")),
);
console.log([...request].map((pair) => JSON.stringify(pair)).join("\n"));
// ['andrew', 'bohdan']
// ['bohdan', 'andrew']