A pure MoonBit Datalog query engine with stratified negation, aggregation, static checks and moon prove formal verification.
Dependencies
moon test # 运行 50 个测试
moon prove verified # 形式化验证(需 Z3 等 SMT 求解器)moon run cmd/main -- examples/ancestor.dl
moon run cmd/main -- examples/graph_reachability.dl
moon run cmd/main -- examples/aggregation.dlWindows 提示:moon prove 前请将 TMP/TEMP 指向不含非 ASCII 字符的目录(如 C:\Temp)。
import {
"haol-05/moondatalog",
}
let src = "edge(a, b). edge(b, c).\npath(X, Y) :- edge(X, Y).\npath(X, Z) :- path(X, Y), edge(Y, Z).\n?- path(a, X).\n"
match @moondatalog.parse(src) {
Err(e) => println(e.to_string())
Ok(program) => match @moondatalog.evaluate(program) {
Err(e) => println(e.to_string())
Ok(result) => {
for t in result.answers[0] {
println(t.to_string()) // (b)\n(c)
}
}
}
}parent(alice, bob).
ancestor(X, Y) :- parent(X, Y).
ancestor(X, Z) :- ancestor(X, Y), parent(Y, Z).
safe(X) :- node(X), not danger(X), X != secret.
dept_size(D, N) :- employee(X, D), N = count : { X }.
?- ancestor(X, carol).| 函数 | 契约 |
|---|---|
| clamp(x, lo, hi) | 返回值在 [lo, hi] 内 |
| bounded_sum(xs, lo, hi) | 总和在 [lo*len, hi*len] 内 |
| index_of_max(xs) | 返回全局最大值的下标 |
A pure MoonBit Datalog query engine with stratified negation, aggregation, static checks and moon prove formal verification.
Dependencies