datalog: dl-clear-idb! helper (208/208)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s

Wipes every rule-headed relation (the IDB) — leaves EDB facts and
rule definitions intact. Useful for inspecting the EDB-only
baseline or for forcing a clean re-saturation.

  (dl-saturate! db)
  (dl-clear-idb! db)        ; ancestor relation now empty
  (dl-saturate! db)         ; re-derives ancestor from parents

2 new api tests verify IDB-wipe and EDB-preservation.
This commit is contained in:
2026-05-08 10:06:48 +00:00
parent 282a3d3d06
commit 9c5a697e45
4 changed files with 50 additions and 6 deletions

View File

@@ -213,3 +213,23 @@
(append! seen h))))
(dl-rules db))
seen))))
;; Wipe every relation that has at least one rule (i.e. every IDB
;; relation) — leaves EDB facts and rule definitions intact. Useful
;; before a follow-up `dl-saturate!` if you want a clean restart, or
;; for inspection of the EDB-only baseline.
(define
dl-clear-idb!
(fn
(db)
(let ((rule-heads (dl-rule-head-rels db)))
(do
(for-each
(fn
(k)
(do
(dict-set! (get db :facts) k (list))
(dict-set! (get db :facts-keys) k {})
(dict-set! (get db :facts-index) k {})))
rule-heads)
db))))