From 3a42438b6844e55efc214d8534c340cf0c467a66 Mon Sep 17 00:00:00 2001 From: Yogthos Date: Mon, 8 Jun 2026 17:22:05 -0400 Subject: [PATCH] =?UTF-8?q?test:=20adapt=20=C2=A76.3=20laziness=20counters?= =?UTF-8?q?=20to=20Option=20A;=20note=20interleave/jolt-r81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Option A makes `take` lazy, so the §6.3 counter tests must force the take result (dorun) to drive realization — an unconsumed take correctly realizes nothing. With that, all 37 lazy-infinite cases pass and the minimal-realization counts match (proving the Option A transformers realize exactly the demanded prefix). interleave kept eager: a lazy (cons-recursive) version leaks its lazy-seq macro expansion under :compile? — the same jolt-r81 bug that blocks lazy reductions/ tree-seq. Documented in 20-coll.clj. Gate: conformance 246x3, lazy-infinite 37/37, fixpoint, self-host, specs+unit green. Co-Authored-By: Claude Opus 4.8 (1M context) --- jolt-core/clojure/core/20-coll.clj | 5 +++- test/integration/lazy-infinite-test.janet | 34 ++++++++++++----------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/jolt-core/clojure/core/20-coll.clj b/jolt-core/clojure/core/20-coll.clj index a716a2f..5fdd597 100644 --- a/jolt-core/clojure/core/20-coll.clj +++ b/jolt-core/clojure/core/20-coll.clj @@ -191,7 +191,10 @@ (defn xml-seq [root] (tree-seq (complement string?) (comp seq :content) root)) -;; Lazy interleave: round-robin one element from each coll until any exhausts. +;; Eager interleave: round-robin one element from each coll until any exhausts. +;; A lazy version (canonical Clojure cons-recursion) hits the same compile-mode +;; overlay bug as reductions/tree-seq — a self-recursive lazy-seq leaks its macro +;; expansion under :compile? (see jolt-r81). Eager until that's fixed. (defn interleave [& colls] (if (empty? colls) (list) diff --git a/test/integration/lazy-infinite-test.janet b/test/integration/lazy-infinite-test.janet index 9bbb427..0e14496 100644 --- a/test/integration/lazy-infinite-test.janet +++ b/test/integration/lazy-infinite-test.janet @@ -61,23 +61,25 @@ ["take 3 interpose :x range" "(quote (0 :x 1))" "(take 3 (interpose :x (range)))"] ["take 3 map vector range iterate" "(quote ([0 100] [1 101] [2 102]))" "(take 3 (map vector (range) (iterate inc 100)))"] - # §6.3 Laziness counter tests — each reads exactly N elements for take N - ["LAZY map" "3" "(do (def c (atom 0)) (take 3 (map (fn [x] (swap! c inc) x) (range))) @c)"] - ["LAZY filter" "6" "(do (def c (atom 0)) (take 3 (filter (fn [x] (swap! c inc) (odd? x)) (range))) @c)"] - ["LAZY remove" "6" "(do (def c (atom 0)) (take 3 (remove (fn [x] (swap! c inc) (even? x)) (range))) @c)"] + # §6.3 Laziness counter tests — realize exactly the demanded prefix. Under + # Option A `take` is lazy, so the take result must be forced (dorun) to drive + # realization; reading the counter without forcing would (correctly) see 0. + ["LAZY map" "3" "(do (def c (atom 0)) (dorun (take 3 (map (fn [x] (swap! c inc) x) (range)))) @c)"] + ["LAZY filter" "6" "(do (def c (atom 0)) (dorun (take 3 (filter (fn [x] (swap! c inc) (odd? x)) (range)))) @c)"] + ["LAZY remove" "6" "(do (def c (atom 0)) (dorun (take 3 (remove (fn [x] (swap! c inc) (even? x)) (range)))) @c)"] ["LAZY take-while" "6" "(do (def c (atom 0)) (dorun (take-while (fn [x] (swap! c inc) (< x 5)) (range))) @c)"] - ["LAZY drop-while" "6" "(do (def c (atom 0)) (take 3 (drop-while (fn [x] (swap! c inc) (< x 5)) (range))) @c)"] - ["LAZY distinct" "4" "(do (def c (atom 0)) (take 3 (distinct (map (fn [x] (swap! c inc) x) (cycle [1 2 1 3 1])))) @c)"] - ["LAZY take-nth" "7" "(do (def c (atom 0)) (take 3 (take-nth 2 (map (fn [x] (swap! c inc) x) (range)))) @c)"] - ["LAZY map-indexed" "3" "(do (def c (atom 0)) (take 3 (map-indexed (fn [i x] (swap! c inc) [i x]) (range))) @c)"] - ["LAZY keep" "6" "(do (def c (atom 0)) (take 3 (keep (fn [x] (swap! c inc) (if (odd? x) x nil)) (range))) @c)"] - ["LAZY keep-indexed" "6" "(do (def c (atom 0)) (take 3 (keep-indexed (fn [i x] (swap! c inc) (if (odd? i) x)) (range))) @c)"] - ["LAZY interpose" "2" "(do (def c (atom 0)) (take 3 (interpose :x (map (fn [x] (swap! c inc) x) (range)))) @c)"] - ["LAZY partition" "6" "(do (def c (atom 0)) (take 3 (partition 2 (map (fn [x] (swap! c inc) x) (range)))) @c)"] - ["LAZY partition-all" "6" "(do (def c (atom 0)) (take 3 (partition-all 2 (map (fn [x] (swap! c inc) x) (range)))) @c)"] - ["LAZY mapcat" "3" "(do (def c (atom 0)) (take 6 (mapcat (fn [x] (swap! c inc) [x x]) (range))) @c)"] - ["LAZY dedupe" "9" "(do (def c (atom 0)) (take 5 (dedupe (map (fn [x] (swap! c inc) x) (cycle [1 1 2 2])))) @c)"] - ["LAZY repeated inc" "3" "(do (def c (atom 0)) (take 3 (map (fn [x] (swap! c inc) x) (iterate inc 0))) @c)"] + ["LAZY drop-while" "6" "(do (def c (atom 0)) (dorun (take 3 (drop-while (fn [x] (swap! c inc) (< x 5)) (range)))) @c)"] + ["LAZY distinct" "4" "(do (def c (atom 0)) (dorun (take 3 (distinct (map (fn [x] (swap! c inc) x) (cycle [1 2 1 3 1]))))) @c)"] + ["LAZY take-nth" "7" "(do (def c (atom 0)) (dorun (take 3 (take-nth 2 (map (fn [x] (swap! c inc) x) (range))))) @c)"] + ["LAZY map-indexed" "3" "(do (def c (atom 0)) (dorun (take 3 (map-indexed (fn [i x] (swap! c inc) [i x]) (range)))) @c)"] + ["LAZY keep" "6" "(do (def c (atom 0)) (dorun (take 3 (keep (fn [x] (swap! c inc) (if (odd? x) x nil)) (range)))) @c)"] + ["LAZY keep-indexed" "6" "(do (def c (atom 0)) (dorun (take 3 (keep-indexed (fn [i x] (swap! c inc) (if (odd? i) x)) (range)))) @c)"] + ["LAZY interpose" "2" "(do (def c (atom 0)) (dorun (take 3 (interpose :x (map (fn [x] (swap! c inc) x) (range))))) @c)"] + ["LAZY partition" "6" "(do (def c (atom 0)) (dorun (take 3 (partition 2 (map (fn [x] (swap! c inc) x) (range))))) @c)"] + ["LAZY partition-all" "6" "(do (def c (atom 0)) (dorun (take 3 (partition-all 2 (map (fn [x] (swap! c inc) x) (range))))) @c)"] + ["LAZY mapcat" "3" "(do (def c (atom 0)) (dorun (take 6 (mapcat (fn [x] (swap! c inc) [x x]) (range)))) @c)"] + ["LAZY dedupe" "9" "(do (def c (atom 0)) (dorun (take 5 (dedupe (map (fn [x] (swap! c inc) x) (cycle [1 1 2 2]))))) @c)"] + ["LAZY repeated inc" "3" "(do (def c (atom 0)) (dorun (take 3 (map (fn [x] (swap! c inc) x) (iterate inc 0)))) @c)"] # Already-working cases (guard against regression) ["take 5 iterate inc" "(quote (0 1 2 3 4))" "(take 5 (iterate inc 0))"]