From a63d67247a1100cf6480108fe542c73c78800632 Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 8 May 2026 09:08:58 +0000 Subject: [PATCH] datalog: add public-API documentation index in datalog.sx --- lib/datalog/datalog.sx | 79 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 lib/datalog/datalog.sx diff --git a/lib/datalog/datalog.sx b/lib/datalog/datalog.sx new file mode 100644 index 00000000..8189ec09 --- /dev/null +++ b/lib/datalog/datalog.sx @@ -0,0 +1,79 @@ +;; lib/datalog/datalog.sx — public API documentation index. +;; +;; This file is reference-only — `load` is an epoch-protocol command, +;; not an SX function, so it cannot reload a list of files from inside +;; another `.sx` file. To set up a fresh sx_server session with all +;; modules in scope, issue these loads in order: +;; +;; (load "lib/datalog/tokenizer.sx") +;; (load "lib/datalog/parser.sx") +;; (load "lib/datalog/unify.sx") +;; (load "lib/datalog/db.sx") +;; (load "lib/datalog/builtins.sx") +;; (load "lib/datalog/aggregates.sx") +;; (load "lib/datalog/strata.sx") +;; (load "lib/datalog/eval.sx") +;; (load "lib/datalog/api.sx") +;; (load "lib/datalog/demo.sx") +;; +;; (lib/datalog/conformance.sh runs this load list automatically.) +;; +;; ── Public API surface ───────────────────────────────────────────── +;; +;; Source / data: +;; (dl-tokenize "src") → token list +;; (dl-parse "src") → parsed clauses +;; (dl-program "src") → db built from a source string +;; (dl-program-data facts rules) → db from SX data lists; rules +;; accept either dict form or +;; list form with `<-` arrow +;; +;; Construction (mutates db): +;; (dl-make-db) empty db +;; (dl-add-fact! db lit) rejects non-ground +;; (dl-add-rule! db rule) rejects unsafe rules +;; (dl-rule head body) dict-rule constructor +;; (dl-add-clause! db clause) parser output → fact or rule +;; (dl-load-program! db src) string source +;; +;; Mutation: +;; (dl-assert! db lit) add + re-saturate +;; (dl-retract! db lit) drop EDB, wipe IDB, re-saturate +;; +;; Query / inspection: +;; (dl-saturate! db) stratified semi-naive default +;; (dl-saturate-naive! db) reference (slow on chains) +;; (dl-saturate-rules! db rules) per-rule-set semi-naive worker +;; (dl-query db goal) list of substitution dicts +;; (dl-relation db rel-name) tuple list for a relation +;; (dl-rules db) rule list +;; (dl-fact-count db) total ground tuples +;; +;; ── Body literal kinds ───────────────────────────────────────────── +;; +;; Positive (rel arg ... arg) +;; Negation {:neg (rel arg ...)} +;; Comparison (< X Y), (<= X Y), (> X Y), (>= X Y), +;; (= X Y), (!= X Y) +;; Arithmetic (is Z (+ X Y)) and (- * /) +;; Aggregation (count R V Goal), (sum R V Goal), +;; (min R V Goal), (max R V Goal), +;; (findall L V Goal) +;; +;; ── Variable conventions ─────────────────────────────────────────── +;; +;; Variables: SX symbols whose first char is uppercase A–Z or '_'. +;; Anonymous '_' is renamed to a fresh _anon per occurrence at +;; rule/query load time so multiple '_' don't unify. +;; +;; ── Demo programs ────────────────────────────────────────────────── +;; +;; See lib/datalog/demo.sx — federation, content, permissions, and +;; the canonical "cooking posts by people I follow (transitively)" +;; example. +;; +;; ── Status ───────────────────────────────────────────────────────── +;; +;; See plans/datalog-on-sx.md — phase-by-phase progress log and +;; roadmap. Run `bash lib/datalog/conformance.sh` to refresh +;; `lib/datalog/scoreboard.{json,md}`.