Step 5: partition-by, dedupe → lazy overlay + trampoline/rand-int overlay

partition-by (10-seq.clj): ported canonical lazy implementation
from CLJS — lazy-seq + cons + take-while, matching Clojure/CLJS
exactly. Fixes the third and final remaining leak from Step 3.

dedupe (20-coll.clj): replaced eager vec-based impl with lazy
step function using lazy-seq + cons. Infinite input no longer hangs.

trampoline (20-coll.clj): pure HOF ported from CLJS — recur until
non-function result. Removed core-trampoline + binding from Janet.

rand-int (20-coll.clj): thin overlay over Janet math/random +
math/floor. Removed core-rand-int + binding from Janet.

Removed core-partition-by + binding from core.janet (now in overlay).

Tests: added dedupe infinite-input case to lazy-infinite harness.
22/22 pass. Conformance 229x3. Specs 32/32.
This commit is contained in:
Yogthos 2026-06-08 11:02:03 -04:00
parent 42da5cef9a
commit 64b1c60939
4 changed files with 37 additions and 31 deletions

View file

@ -22,3 +22,15 @@
(if (next s)
(recur (conj ret (first s)) (next s))
(seq ret))))
;; Lazy partition-by: groups consecutive elements by (f x), matching Clojure/CLJS.
(defn partition-by [f coll]
(let [step (fn step [s]
(lazy-seq
(let [s (seq s)]
(when s
(let [fst (first s)
fv (f fst)
run (cons fst (take-while (fn [x] (= fv (f x))) (rest s)))]
(cons run (step (lazy-seq (drop (count run) s)))))))))]
(step coll)))