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
|
|
@ -3509,4 +3509,6 @@
|
|||
{:suite "protocols / instance? matches dispatch" :label "instance? agrees with what a value's class implements" :expected "[true true false true true]" :actual "[(instance? clojure.lang.Associative [1 2]) (instance? clojure.lang.IFn :k) (instance? java.util.Map [1 2]) (instance? clojure.lang.Seqable (map inc [1 2])) (instance? clojure.lang.IPersistentVector [1 2])]"}
|
||||
{:suite "class / hierarchy views agree" :label "isa?/supers see the modeled exception + collection hierarchy" :expected "[true true true true]" :actual "[(isa? clojure.lang.ExceptionInfo java.lang.RuntimeException) (contains? (supers java.lang.NumberFormatException) java.lang.RuntimeException) (isa? clojure.lang.Keyword clojure.lang.IFn) (contains? (ancestors clojure.lang.PersistentVector) java.util.List)]"}
|
||||
{:suite "host-interop / getClass" :label ".getClass is a universal Object method, reached on every value type" :expected "[\"java.util.Date\" \"java.io.File\"]" :actual "[(.getName (.getClass (java.util.Date.))) (.getName (.getClass (java.io.File. \"x\")))]"}
|
||||
{:suite "reduce / IReduceInit" :label "reduce drives a deftype's own reduce method (init arity)" :expected "110" :actual "(do (deftype Rng [n] clojure.lang.IReduceInit (reduce [_ f init] (loop [i 0 acc init] (if (< i n) (recur (inc i) (f acc i)) acc)))) (reduce + 100 (->Rng 5)))"}
|
||||
{:suite "reduce / IReduceInit" :label "a deftype reduce honors reduced short-circuit" :expected "3" :actual "(do (deftype Rng [n] clojure.lang.IReduceInit (reduce [_ f init] (loop [i 0 acc init] (if (< i n) (let [a (f acc i)] (if (reduced? a) @a (recur (inc i) a))) acc)))) (reduce (fn [acc x] (if (= x 3) (reduced acc) (+ acc x))) 0 (->Rng 10)))"}
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue