Collection fns: JVM-faithful return types + laziness (#219)
A type-aware audit (~190 collection expressions vs reference Clojure) found four divergences the corpus missed — value-equality (= [0 1] '(0 1)) hides type and laziness differences. Fixed, with type-predicate + over-infinite corpus rows that pin them. - partition-all [n coll] built vector chunks; JVM chunks are seqs. (The [n step coll] arity was already correct, as is the partition-all transducer, whose chunks are vectors in JVM too.) Now builds seq chunks. - replace always returned a vector (mapv) and was eager; JVM is type-preserving — a vector maps to a vector, any other seqable to a lazy seq. - sequence eagerly realized its source (into-xform), so (first (sequence (map inc) (range))) hung. Rewrote as a transformer iterator: pull one input at a time, buffer the step outputs, emit lazily, run the completion to flush a stateful xform. eduction builds on it (lazy, no longer an eager vector). - mapcat and (apply concat coll-of-colls) hung over an infinite source because jolt-apply seq->lists the trailing arg and mapcat seq->lists the map result. Added lazy-concat-seq (lazily flatten a seq of colls); mapcat uses it directly, and apply special-cases concat (its result is lazy) to route through it. Docs: a cross-cutting return-type + laziness contract in docs/spec/09-core-library; SPEC.md notes that = masks type/laziness so they need predicate / over-infinite rows. EBNF is reader syntax only — unaffected. Seed change (partition-all/replace/eduction are clojure.core overlay) -> re-mint; selfhost holds. make test + shakesmoke + buildsmoke green, 0 new divergences. Co-authored-by: Yogthos <yogthos@gmail.com>
This commit is contained in:
parent
8180c85393
commit
f3084f8043
11 changed files with 810 additions and 679 deletions
|
|
@ -210,7 +210,12 @@
|
|||
true))
|
||||
false)))
|
||||
|
||||
(defn replace [smap coll] (mapv (fn [x] (get smap x x)) coll))
|
||||
;; A vector input maps to a vector (eager); any other coll to a lazy seq — JVM
|
||||
;; replace is type-preserving, not vector-always.
|
||||
(defn replace [smap coll]
|
||||
(if (vector? coll)
|
||||
(mapv (fn [x] (get smap x x)) coll)
|
||||
(map (fn [x] (get smap x x)) coll)))
|
||||
|
||||
(defn nthnext [coll n]
|
||||
(loop [n n xs (seq coll)]
|
||||
|
|
|
|||
|
|
@ -271,14 +271,17 @@
|
|||
|
||||
;; eduction is EAGER on jolt (documented divergence): the composed
|
||||
;; xforms applied to coll, realized into a vector.
|
||||
;; A lazy application of the composed xforms to coll (sequence is lazy now), so an
|
||||
;; infinite or expensive source isn't realized up front. Not a re-iterable Eduction
|
||||
;; object, but reduce / into / seq / first over it all work.
|
||||
(defn eduction [& args]
|
||||
(let [coll (last args)
|
||||
xforms (butlast args)]
|
||||
(if xforms
|
||||
(into [] (apply comp xforms) coll)
|
||||
(into [] coll))))
|
||||
(sequence (apply comp xforms) coll)
|
||||
(sequence coll))))
|
||||
|
||||
(defn ->Eduction [xform coll] (into [] xform coll))
|
||||
(defn ->Eduction [xform coll] (sequence xform coll))
|
||||
|
||||
;; --- JVM-shape stubs and trivial shells --------------------------------------
|
||||
;; Pure compositions or documented jolt stubs; the host keeps nothing.
|
||||
|
|
|
|||
|
|
@ -125,10 +125,13 @@
|
|||
(letfn [(go [s]
|
||||
(lazy-seq
|
||||
(when (seq s)
|
||||
(loop [i 0 chunk [] cur s]
|
||||
;; realize exactly n via first/rest (minimal realization), but emit
|
||||
;; the chunk as a SEQ — JVM partition-all chunks are seqs, not
|
||||
;; vectors (partitionv-all is the vector variant).
|
||||
(loop [i 0 acc () cur s]
|
||||
(if (and (< i n) (seq cur))
|
||||
(recur (inc i) (conj chunk (first cur)) (rest cur))
|
||||
(cons chunk (go cur)))))))]
|
||||
(recur (inc i) (cons (first cur) acc) (rest cur))
|
||||
(cons (reverse acc) (go cur)))))))]
|
||||
(go coll)))
|
||||
([n step coll]
|
||||
(letfn [(go [s]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue