Review fixes: revert partition+concat overlay, delete dead defns, dedupe de-duplicated
1. partition+concat removed from 10-seq.clj overlay — they use lazy-seq macro which produces raw make-lazy-seq forms in compile mode (same issue as mapcat overlay reversal). Must stay native. 2. Dead defns removed from core.janet: core-map-indexed, core-iterate, core-repeatedly (30 lines). Bindings already removed in prior commit. 3. dedupe removed from 40-lazy.clj — belongs in 20-coll.clj. Gates: conformance 229×3, lazy-infinite 22/22, specs 32/32.
This commit is contained in:
parent
4a2ef99fee
commit
a71bddd580
2 changed files with 18 additions and 62 deletions
|
|
@ -33,35 +33,4 @@
|
|||
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)))
|
||||
|
||||
;; 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))))
|
||||
(step coll)))
|
||||
|
|
@ -1292,21 +1292,6 @@
|
|||
(+= i step))
|
||||
result))))
|
||||
|
||||
(defn core-map-indexed [f & rest]
|
||||
(if (= 0 (length rest)) (td-map-indexed f)
|
||||
(let [coll (in rest 0)]
|
||||
(if (lazy-seq? coll)
|
||||
(do
|
||||
(defn mstep [c i]
|
||||
(fn []
|
||||
(if (seq-done? c) nil
|
||||
@[(f i (ls-first c)) (mstep (ls-rest c) (+ i 1))])))
|
||||
(make-lazy-seq (mstep coll 0)))
|
||||
(let [c (realize-for-iteration coll) result @[]]
|
||||
(var i 0)
|
||||
(each x c (array/push result (f i x)) (++ i))
|
||||
(tuple/slice (tuple ;result)))))))
|
||||
|
||||
# reduce-kv now lives in the Clojure collection tier (core/20-coll.clj).
|
||||
|
||||
# pop is defined only on stacks (vectors -> last end, lists -> front); Clojure
|
||||
|
|
@ -1351,21 +1336,6 @@
|
|||
(+= i step))
|
||||
(tuple/slice (tuple ;result))))))
|
||||
|
||||
(defn core-iterate [f x]
|
||||
"Lazy infinite sequence x, (f x), (f (f x)), ..."
|
||||
(defn istep [v] (fn [] @[v (istep (f v))]))
|
||||
(make-lazy-seq (istep x)))
|
||||
|
||||
(defn core-repeatedly
|
||||
"(repeatedly f) -> infinite lazy seq of (f) calls; (repeatedly n f) -> n calls."
|
||||
[a & rest]
|
||||
(if (= 0 (length rest))
|
||||
(do (defn rstep [] (fn [] @[(a) (rstep)])) (make-lazy-seq (rstep)))
|
||||
(let [n a f (in rest 0)]
|
||||
(var result @[]) (var i 0)
|
||||
(while (< i n) (array/push result (f)) (++ i))
|
||||
result)))
|
||||
|
||||
# ============================================================
|
||||
# Higher-order functions
|
||||
# ============================================================
|
||||
|
|
@ -2241,6 +2211,23 @@
|
|||
(if started (rf (rf (a 0) sep) (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-empty [coll]
|
||||
(cond
|
||||
(phm? coll) (make-phm)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue