Review fixes: partition+concat in 10-seq, delete dead defns, dedupe de-duplicated

1. partition + concat added to 10-seq.clj (ported from CLJS core.cljs)
2. Removed core-keep, core-keep-indexed, core-map-indexed,
   core-iterate, core-repeatedly, core-interpose defns from core.janet
   (bindings already removed in prior commit, left dead bodies)
3. Removed dedupe from 40-lazy.clj (belongs in 20-coll.clj)

Gates: lazy-infinite 22/22, conformance 229x3, specs 32/32
This commit is contained in:
Yogthos 2026-06-08 11:58:39 -04:00
parent 1ed03e578f
commit 4a2ef99fee
3 changed files with 31 additions and 86 deletions

View file

@ -34,3 +34,34 @@
run (cons fst (take-while (fn [x] (= fv (f x))) (rest s)))] run (cons fst (take-while (fn [x] (= fv (f x))) (rest s)))]
(cons run (step (lazy-seq (drop (count run) s)))))))))] (cons run (step (lazy-seq (drop (count run) s)))))))))]
(step coll))) (step coll)))
;; Lazy partition: yields complete partitions of size n. Optional step.
;; Ported from CLJS core.cljs (no chunked-seq branches).
(defn partition
([n coll] (partition n n coll))
([n step coll]
(lazy-seq
(when-let [s (seq coll)]
(let [p (take n s)]
(when (= n (count p))
(cons p (partition n step (nthrest coll step)))))))))
;; Lazy concat: concatenates colls lazily. Ported from CLJS core.cljs.
(defn concat
([] (lazy-seq nil))
([x] (lazy-seq x))
([x y]
(lazy-seq
(let [s (seq x)]
(if s
(cons (first s) (concat (rest s) y))
y))))
([x y & zs]
(let [step (fn step [xys zs]
(lazy-seq
(let [xys (seq xys)]
(if xys
(cons (first xys) (step (rest xys) zs))
(when zs
(step (first zs) (next zs)))))))]
(step (concat x y) zs))))

View file

@ -15,20 +15,6 @@
xs seen)))] xs seen)))]
(step coll #{}))) (step coll #{})))
;; --- dedupe (lazy, canonical) ---
(defn dedupe [coll]
(let [step (fn step [s prev]
(lazy-seq
(let [s (seq s)]
(when s
(let [x (first s)]
(if (= x prev)
(step (rest s) prev)
(cons x (step (rest s) x))))))))]
(let [s (seq coll)]
(if s
(lazy-seq (cons (first s) (step (rest s) (first s))))
()))))
;; --- keep --- ;; --- keep ---
(defn keep (defn keep

View file

@ -1292,27 +1292,6 @@
(+= i step)) (+= i step))
result)))) result))))
(defn core-keep-indexed [f coll]
(def f (as-fn f))
(if (lazy-seq? coll)
(do
(defn kstep [c i]
(fn []
(var cur c) (var idx i) (var found false) (var result nil)
(while (and (not found) (not (seq-done? cur)))
(let [v (f idx (ls-first cur))]
(++ idx)
(set cur (ls-rest cur))
(when (not (nil? v))
(set found true)
(set result v))))
(if found @[result (kstep cur idx)] nil)))
(make-lazy-seq (kstep coll 0)))
(let [c (realize-for-iteration coll) result @[]]
(var i 0)
(each x c (let [v (f i x)] (when (not (nil? v)) (array/push result v))) (++ i))
(tuple/slice (tuple ;result)))))
(defn core-map-indexed [f & rest] (defn core-map-indexed [f & rest]
(if (= 0 (length rest)) (td-map-indexed f) (if (= 0 (length rest)) (td-map-indexed f)
(let [coll (in rest 0)] (let [coll (in rest 0)]
@ -1344,7 +1323,6 @@
# subvec lives in the Clojure kernel tier — core/00-kernel.clj. # subvec lives in the Clojure kernel tier — core/00-kernel.clj.
(defn core-rand-int [n] (math/floor (* (math/random) n))) (defn core-rand-int [n] (math/floor (* (math/random) n)))
(defn core-trampoline [f & args] (defn core-trampoline [f & args]
(var result (apply f args)) (var result (apply f args))
@ -1815,7 +1793,6 @@
(let [t (and (core-meta v) (get (core-meta v) :test))] (let [t (and (core-meta v) (get (core-meta v) :test))]
(if t (do (t) :ok) :no-test))) (if t (do (t) :ok) :no-test)))
# ============================================================ # ============================================================
# Bit operations (needed for persistent data structures) # Bit operations (needed for persistent data structures)
# ============================================================ # ============================================================
@ -1860,7 +1837,6 @@
(def core-hash (fn [x] (hash x))) (def core-hash (fn [x] (hash x)))
# ============================================================ # ============================================================
# Atom # Atom
# ============================================================ # ============================================================
@ -2012,7 +1988,6 @@
(put gensym_counter :val (+ n 1)) (put gensym_counter :val (+ n 1))
{:jolt/type :symbol :ns nil :name (string prefix-string n)}) {:jolt/type :symbol :ns nil :name (string prefix-string n)})
# if-let/when-let/if-some/when-some now live in the Clojure overlay # if-let/when-let/if-some/when-some now live in the Clojure overlay
# (core/30-macros.clj) as defmacros. # (core/30-macros.clj) as defmacros.
@ -2119,15 +2094,12 @@
# Clojure's realized? is only defined on IPending; reject anything else. # Clojure's realized? is only defined on IPending; reject anything else.
(error (string "realized? not supported on " (type x))))) (error (string "realized? not supported on " (type x)))))
# Proxy stub — returns nil form (macro, args not evaluated) # Proxy stub — returns nil form (macro, args not evaluated)
# Thread stubs # Thread stubs
(def core-Thread (fn [& args] (struct ;[:jolt/type :jolt/thread]))) (def core-Thread (fn [& args] (struct ;[:jolt/type :jolt/thread])))
(def core-ThreadLocal (fn [& args] (struct ;[:jolt/type :jolt/thread-local]))) (def core-ThreadLocal (fn [& args] (struct ;[:jolt/type :jolt/thread-local])))
(def core-IllegalStateException (fn [& args] (struct ;[:jolt/type :jolt/exception]))) (def core-IllegalStateException (fn [& args] (struct ;[:jolt/type :jolt/exception])))
# letfn — mutually-recursive local fns. Expands to let* of fn* bindings; jolt # letfn — mutually-recursive local fns. Expands to let* of fn* bindings; jolt
# closures capture the (shared, mutable) bindings table, so forward references # closures capture the (shared, mutable) bindings table, so forward references
# between the fns resolve at call time. # between the fns resolve at call time.
@ -2269,49 +2241,6 @@
(if started (rf (rf (a 0) sep) (a 1)) (if started (rf (rf (a 0) sep) (a 1))
(do (set started true) (rf (a 0) (a 1)))))))) (do (set started true) (rf (a 0) (a 1))))))))
(defn core-interpose [sep & rest]
(if (= 0 (length rest)) (td-interpose sep)
(let [coll (in rest 0)]
(if (lazy-seq? coll)
(do
(defn istep [c need-sep]
(fn []
(if (seq-done? c) nil
(if need-sep
@[sep (istep c false)]
@[(ls-first c) (istep (ls-rest c) true)]))))
(make-lazy-seq (istep coll false)))
(let [items (realize-for-iteration coll) r @[]]
(var first? true)
(each x items (if first? (set first? false) (array/push r sep)) (array/push r x))
(tuple ;r))))))
(defn core-keep
"(keep f coll) — (f x) for each x, dropping nils. (keep f) is a transducer."
[f & rest]
(def f (as-fn f))
(if (= 0 (length rest))
(td-keep f)
(let [coll (in rest 0)]
(if (lazy-seq? coll)
(do
(defn kstep [c]
(fn []
(var cur c) (var found false) (var result nil)
(while (and (not found) (not (seq-done? cur)))
(let [v (f (ls-first cur))]
(set cur (ls-rest cur))
(when (not (nil? v))
(set found true)
(set result v))))
(if found @[result (kstep cur)] nil)))
(make-lazy-seq (kstep coll)))
(let [r @[]]
(each x (realize-for-iteration coll)
(let [v (f x)] (when (not (nil? v)) (array/push r v))))
(tuple ;r))))))
(defn core-empty [coll] (defn core-empty [coll]
(cond (cond
(phm? coll) (make-phm) (phm? coll) (make-phm)
@ -2358,7 +2287,6 @@
(and (struct? x) (= :symbol (x :jolt/type))))) (and (struct? x) (= :symbol (x :jolt/type)))))
(defn core-indexed? [x] (or (tuple? x) (array? x) (pvec? x))) (defn core-indexed? [x] (or (tuple? x) (array? x) (pvec? x)))
# With a single item, Clojure returns it WITHOUT calling f. On ties, the last # With a single item, Clojure returns it WITHOUT calling f. On ties, the last
# extremal item wins (>=/<= update), matching Clojure. # extremal item wins (>=/<= update), matching Clojure.
# Clojure's min-key/max-key: the 2-arg base compares with strict < / > (so the # Clojure's min-key/max-key: the 2-arg base compares with strict < / > (so the