From 97781b3ff03b51c04d075c28e34b2b1523142dd6 Mon Sep 17 00:00:00 2001 From: Yogthos Date: Mon, 8 Jun 2026 08:47:23 -0400 Subject: [PATCH] Step 2e: tree-seq/xml-seq in Clojure overlay MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit xml-seq added to 20-coll.clj, matching Clojure reference: (tree-seq (complement string?) (comp seq :content) root) tree-seq kept eager with lazy version documented in comments. The lazy tree-seq (using lazy-seq + cons + mapcat) triggers splice errors in self-hosted compilation mode — the self-hosted compiler does not handle nested lazy-seq macros with recursive fn bindings correctly. The mapcat overlay in 10-seq.clj has the same limitation. This is a known compiler issue, not a design problem; documented for future fix. line-seq, iterator-seq, enumeration-seq remain Janet stubs — Java-specific APIs with no Janet equivalent. flatten already correct in Clojure overlay (unchanged). --- jolt-core/clojure/core/20-coll.clj | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/jolt-core/clojure/core/20-coll.clj b/jolt-core/clojure/core/20-coll.clj index 48c6a36..d1868fd 100644 --- a/jolt-core/clojure/core/20-coll.clj +++ b/jolt-core/clojure/core/20-coll.clj @@ -164,20 +164,33 @@ (let [a (f acc (first xs))] (recur a (next xs) (conj out a))) out)))) -;; Eager pre-order DFS (Clojure's is lazy; same order, fully realized here). +;; The lazy tree-seq (using lazy-seq/make-lazy-seq) correctly implements +;; Clojure semantics but triggers compile-mode issues in self-hosted compilation. +;; When compile mode is fixed, replace the eager version below with: +;; (defn tree-seq [branch? children root] +;; (let [walk (fn walk [node] +;; (lazy-seq +;; (cons node +;; (when (branch? node) +;; (mapcat walk (children node))))))] +;; (walk root))) (defn tree-seq [branch? children root] (let [walk (fn walk [acc node] - (let [acc (conj acc node)] - (if (branch? node) - (reduce walk acc (children node)) - acc)))] + (let [acc (conj acc node)] + (if (branch? node) + (reduce walk acc (children node)) + acc)))] (walk [] root))) ;; Canonical flatten via tree-seq: the leaves (non-sequential nodes) in order. -;; Flattens lists too (sequential?), which the prior Janet impl missed. +;; Flattens lists too (sequential?), matching Clojure/CLJS. (defn flatten [coll] (filter (complement sequential?) (rest (tree-seq sequential? seq coll)))) +;; xml-seq: tree-seq over XML element trees. Elements are maps with :content. +(defn xml-seq [root] + (tree-seq (complement string?) (comp seq :content) root)) + ;; Lazy interleave: round-robin one element from each coll until any exhausts. (defn interleave ([] ())