relations: Phase 1 schema + direct relations (rel facts, relate/unrelate, children/parents/related) + 22 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m15s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m15s
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
40
lib/relations/schema.sx
Normal file
40
lib/relations/schema.sx
Normal file
@@ -0,0 +1,40 @@
|
||||
;; lib/relations/schema.sx — relationship fact vocabulary over lib/datalog/.
|
||||
;;
|
||||
;; relations is content-agnostic: a node is an opaque id (a symbol or string);
|
||||
;; domains own what ids mean. A relationship is a single Datalog fact
|
||||
;;
|
||||
;; rel(Src, Dst, Kind)
|
||||
;;
|
||||
;; meaning "Src is related to Dst under Kind" (read directionally: Src is the
|
||||
;; parent/owner/origin, Dst the child/member/reply). Kind is an open vocabulary;
|
||||
;; the names below are the platform's well-known kinds but relate accepts any
|
||||
;; kind symbol — Datalog is untyped and domains may coin their own.
|
||||
|
||||
(define relations-kinds (quote (parent member reply variant origin link)))
|
||||
|
||||
(define relations-rel (fn (src dst kind) (list (quote rel) src dst kind)))
|
||||
|
||||
(define relations-rel-src (fn (f) (nth f 1)))
|
||||
|
||||
(define relations-rel-dst (fn (f) (nth f 2)))
|
||||
|
||||
(define relations-rel-kind (fn (f) (nth f 3)))
|
||||
|
||||
(define
|
||||
relations-member?
|
||||
(fn
|
||||
(x xs)
|
||||
(cond
|
||||
((= (len xs) 0) false)
|
||||
((= (first xs) x) true)
|
||||
(else (relations-member? x (rest xs))))))
|
||||
|
||||
(define
|
||||
relations-known-kind?
|
||||
(fn (k) (relations-member? k relations-kinds)))
|
||||
|
||||
(define
|
||||
relations-fact-valid?
|
||||
(fn
|
||||
(f)
|
||||
(and (list? f) (= (len f) 4) (= (first f) (quote rel)))))
|
||||
Reference in New Issue
Block a user