Route deftype/reify interface dispatch through one seam
The "does value V declare method M; if so call it" decision was re-derived in a dozen places with two different lookup helpers — records.ss jrec-cl and collections.ss rec-coll-method were a byte-for-byte duplicate — and reduce only honored a reify's own reduce method, not a deftype's: (reduce + 100 (->Rng 5)) ; Rng deftype implementing IReduceInit => "not seqable" ; JVM: 110 Add iface-method / iface-call: one lookup that resolves a method for a deftype OR a reify, with arity, and is the seam a core fn's interface arm collapses to. jrec-cl now aliases rec-coll-method (the duplicate is gone). reduce routes its IReduceInit arm through iface-method, so a deftype's reduce drives the reduction like a reify's, reduced short-circuit included. Runtime only, no re-mint. make test green (0 new/stale), +2 corpus rows.
This commit is contained in:
parent
0b07b376bb
commit
01f98c2e89
3 changed files with 25 additions and 5 deletions
|
|
@ -421,11 +421,11 @@
|
|||
(if (jolt-nil? s) (jolt-invoke f) ; (reduce f []) -> (f)
|
||||
(reduce-seq f (seq-first s) (jolt-seq (seq-more s))))))
|
||||
((f init coll)
|
||||
;; IReduceInit: a reify/record with its own `reduce` method drives the
|
||||
;; reduction (reduce f init (reify clojure.lang.IReduceInit (reduce [_ f i] ...))).
|
||||
;; IReduceInit: a deftype/record OR reify with its own `reduce` method drives
|
||||
;; the reduction, e.g. (reduce f init (reify clojure.lang.IReduceInit
|
||||
;; (reduce [_ f i] ...))) or the same on a deftype.
|
||||
(cond
|
||||
((and (jreify? coll) (reified-methods coll)
|
||||
(hashtable-ref (reified-methods coll) "reduce" #f))
|
||||
((iface-method coll "reduce" 3)
|
||||
=> (lambda (m) (let ((r (jolt-invoke m coll f init)))
|
||||
(if (jolt-reduced? r) (jolt-reduced-val r) r))))
|
||||
(else (reduce-seq f init (jolt-seq coll)))))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue