refactor: registry pattern for jolt-get + jolt=2 (jolt-lmot)
jolt-get (4 sites: host-table/natives-misc/inst-time/records) and jolt=2 (6 sites: records/vars/inst-time/natives-misc/bigdec/host-table) move off the set!-rebind chains to register-get-arm! / register-eq-arm!. get's case-lambda becomes a stable 2/3-arg entry over a 3-arg dispatch; the equality arm pred is (a b) since either arg may carry the type, and the host-table sorted arm normalizes-then-re-dispatches. Behaviour-preserving (runtime .ss): var/inst/bigdec/record/uuid equality, record!=map, sorted-map=plain-map, and all the get cases verified; make test green, 0 new corpus divergences. Four of six dispatchers done; the printer (pr-str/pr-readable) remains.
This commit is contained in:
parent
d168d1195b
commit
acf3e1ffd3
8 changed files with 63 additions and 65 deletions
|
|
@ -43,7 +43,15 @@
|
|||
;; chars/strings: Chez natives (strings treated immutable).
|
||||
|
||||
;; --- jolt equality (Clojure =) — scalars + collections ----------------------
|
||||
(define (jolt=2 a b)
|
||||
;; A host shim registers a type's equality via register-eq-arm! instead of
|
||||
;; set!-wrapping jolt=2 (cf. register-hash-arm!). An arm is (pred . handler), both
|
||||
;; (a b): the arm applies when pred holds (typically either arg is the type), and
|
||||
;; handler returns the #t/#f result. Arms are checked before the base scalar/coll
|
||||
;; cases; the entry is stable.
|
||||
(define jolt-eq-arms '())
|
||||
(define (register-eq-arm! pred handler)
|
||||
(set! jolt-eq-arms (cons (cons pred handler) jolt-eq-arms)))
|
||||
(define (jolt=2-base a b)
|
||||
(cond
|
||||
((and (jolt-nil? a) (jolt-nil? b)) #t)
|
||||
((or (jolt-nil? a) (jolt-nil? b)) #f)
|
||||
|
|
@ -63,6 +71,11 @@
|
|||
;; other collections (map/set): forward to collections.ss.
|
||||
((and (jolt-coll? a) (jolt-coll? b)) (jolt-coll=? a b))
|
||||
(else (eq? a b))))
|
||||
(define (jolt=2 a b)
|
||||
(let loop ((as jolt-eq-arms))
|
||||
(cond ((null? as) (jolt=2-base a b))
|
||||
(((caar as) a b) ((cdar as) a b))
|
||||
(else (loop (cdr as))))))
|
||||
(define (jolt= a . rest)
|
||||
(let loop ((a a) (rest rest))
|
||||
(cond ((null? rest) #t)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue