relations: Phase 2 reachability + roots/leaves + cycles (engine.sx, kind-parameterized closure) + 24 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m0s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m0s
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,25 +1,18 @@
|
||||
;; lib/relations/api.sx — relationship lifecycle + direct queries over lib/datalog/.
|
||||
;; lib/relations/api.sx — relationship lifecycle + queries over lib/datalog/.
|
||||
;;
|
||||
;; A relations db is a live Datalog db holding rel(Src,Dst,Kind) facts. Phase 1
|
||||
;; uses no rules — direct children/parents are plain queries on the rel
|
||||
;; relation. Phase 2's engine.sx adds recursive reachability rules; build-db
|
||||
;; will fold them in then.
|
||||
;; A relations db is a live Datalog db holding rel(Src,Dst,Kind) facts under the
|
||||
;; engine ruleset (lib/relations/engine.sx). Direct children/parents are plain
|
||||
;; queries on the rel relation; transitive reachability/roots/leaves/cycles come
|
||||
;; from the engine's recursive rules.
|
||||
;;
|
||||
;; Two surfaces: db-threading core fns (relations-children-of db ...) and a
|
||||
;; current-db convenience layer (relations/relate ...) for callers that load a
|
||||
;; fact base once and query without passing the db around. This mirrors lib/acl.
|
||||
|
||||
(define relations-rules (list))
|
||||
|
||||
(define
|
||||
relations-build-db
|
||||
(fn (facts) (dl-program-data facts relations-rules)))
|
||||
|
||||
;; Pull one column (by keyword key) out of a list of substitution dicts.
|
||||
(define
|
||||
relations-pluck
|
||||
(fn (substs key) (map (fn (s) (get s key)) substs)))
|
||||
|
||||
;; Direct children: every Dst with rel(node, Dst, kind).
|
||||
(define
|
||||
relations-children-of
|
||||
@@ -94,3 +87,31 @@
|
||||
(define
|
||||
relations/related
|
||||
(fn (node kind) (relations-related (relations-ensure-db!) node kind)))
|
||||
|
||||
(define
|
||||
relations/descendants
|
||||
(fn (node kind) (relations-descendants (relations-ensure-db!) node kind)))
|
||||
|
||||
(define
|
||||
relations/ancestors
|
||||
(fn (node kind) (relations-ancestors (relations-ensure-db!) node kind)))
|
||||
|
||||
(define
|
||||
relations/reachable?
|
||||
(fn (a b kind) (relations-reachable? (relations-ensure-db!) a b kind)))
|
||||
|
||||
(define
|
||||
relations/roots
|
||||
(fn (kind) (relations-roots (relations-ensure-db!) kind)))
|
||||
|
||||
(define
|
||||
relations/leaves
|
||||
(fn (kind) (relations-leaves (relations-ensure-db!) kind)))
|
||||
|
||||
(define
|
||||
relations/cycle?
|
||||
(fn (node kind) (relations-cycle? (relations-ensure-db!) node kind)))
|
||||
|
||||
(define
|
||||
relations/acyclic?
|
||||
(fn (kind) (relations-acyclic? (relations-ensure-db!) kind)))
|
||||
|
||||
Reference in New Issue
Block a user