core: migrate partition-all to the Clojure overlay (minimal realization)
Resolves the deferred partition-all port (jolt-yo3). The earlier CLJ attempt via lazy take/drop over-realized vs the Janet pstep, tripping the §6.3 laziness counter. The collection arities now realize EXACTLY n per chunk with a first/rest loop and continue from the advanced cursor (no re-drop), so (take 3 (partition-all 2 (map counting (range)))) realizes exactly 6 — matching minimal realization in both interpret and compile modes. Keeps transducer + [n coll] + [n step coll] arities. letfn-bound recursion sidesteps the compile-mode multi-arity closure bug (jolt-zxw), like keep-indexed/map-indexed. Removed from the Janet seed: core-partition-all + its binding + the now-dead td-partition-all helper (the CLJ version carries its own transducer arity). Gate: conformance 262x3, lazy-infinite 44/44 (incl the §6.3 partition-all counter), clojure-test-suite 4004/66, fixpoint, self-host, specs+unit green.
This commit is contained in:
parent
2c31a9e3bc
commit
cab1a75b75
2 changed files with 39 additions and 38 deletions
|
|
@ -100,7 +100,40 @@
|
|||
(lazy-seq (cons x (iterate f (f x)))))
|
||||
|
||||
|
||||
;; partition-all stays in the Janet seed for now (core-partition-all): it already
|
||||
;; has the transducer + collection arities (jolt-cru), and a CLJ port realizes a
|
||||
;; different (non-minimal) element count via take/drop than the Janet one,
|
||||
;; tripping the §6.3 laziness counters + a suite file. Ported separately.
|
||||
;; --- partition-all --- (transducer + [n coll] + [n step coll])
|
||||
;; The collection arities realize EXACTLY n per chunk via a first/rest loop and
|
||||
;; continue from the advanced cursor (not a re-drop), so they realize minimally
|
||||
;; — matching the Janet pstep the §6.3 laziness counters were written against.
|
||||
;; letfn-bound `go` (not arity-direct recursion) sidesteps the compile-mode
|
||||
;; multi-arity closure-capture bug (jolt-zxw), as keep-indexed/map-indexed do.
|
||||
(defn partition-all
|
||||
([n]
|
||||
(fn [rf]
|
||||
(let [a (volatile! [])]
|
||||
(fn
|
||||
([] (rf))
|
||||
([result]
|
||||
(let [result (if (zero? (count @a))
|
||||
result
|
||||
(let [v @a] (vreset! a []) (unreduced (rf result v))))]
|
||||
(rf result)))
|
||||
([result input]
|
||||
(vswap! a conj input)
|
||||
(if (= n (count @a))
|
||||
(let [v @a] (vreset! a []) (rf result v))
|
||||
result))))))
|
||||
([n coll]
|
||||
(letfn [(go [s]
|
||||
(lazy-seq
|
||||
(when (seq s)
|
||||
(loop [i 0 chunk [] cur s]
|
||||
(if (and (< i n) (seq cur))
|
||||
(recur (inc i) (conj chunk (first cur)) (rest cur))
|
||||
(cons chunk (go cur)))))))]
|
||||
(go coll)))
|
||||
([n step coll]
|
||||
(letfn [(go [s]
|
||||
(lazy-seq
|
||||
(when (seq s)
|
||||
(cons (take n s) (go (nthrest s step))))))]
|
||||
(go coll))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue