JVM-semantics fixes and small cleanups

- take-last / drop-last return seqs, not vectors: take-last wraps in seq; drop-last
  is the JVM (map (fn [x _] x) coll (drop n coll)) form (lazy, () when empty).
- cycle is lazy ((lazy-seq (concat coll (cycle coll)))) so it no longer counts its
  argument and terminates on a lazy/infinite input.
- fold's foldable-call catch uses :default, matching the rest of jolt-core and
  also catching a raw host condition from a folding primitive.
- alts! rejects non-channel ports with a clear error (put specs / :default are
  unsupported) instead of crashing inside ac-poll!.
- Misc: drop the unreachable second getCause clause; jolt-nth on a string raises
  'nth "index out of bounds" like the vector branch; name the inline fixpoint cap;
  bld-sh-capture rejoins lines with newlines; clarify a couple of comments.
This commit is contained in:
Yogthos 2026-06-23 01:36:51 -04:00
parent 524d4cd8d1
commit 14547bd1d5
11 changed files with 642 additions and 616 deletions

View file

@ -188,13 +188,15 @@
(defn replicate [n x] (map (fn [_] x) (range n)))
;; Returns a seq (JVM does), nil when n<=0 or coll is empty.
(defn take-last [n coll]
(let [c (vec coll) len (count c)]
(when (pos? len) (subvec c (max 0 (- len n))))))
(when (pos? len) (seq (subvec c (max 0 (- len n)))))))
;; The JVM definition: a lazy seq (() when empty), not a vector.
(defn drop-last
([coll] (drop-last 1 coll))
([n coll] (let [c (vec coll)] (subvec c 0 (max 0 (- (count c) n))))))
([n coll] (map (fn [x _] x) coll (drop n coll))))
(defn distinct?
([x] true)

View file

@ -76,13 +76,11 @@
(mapi 0 coll))))
;; --- cycle ---
;; Lazy, like the JVM: never counts coll, so it terminates on a lazy/infinite
;; argument instead of forcing it.
(defn cycle [coll]
(if-let [vals (seq coll)]
(let [n (count vals)]
(letfn [(cstep [i]
(lazy-seq
(cons (nth vals (mod i n)) (cstep (inc i)))))]
(cstep 0)))
(if (seq coll)
(lazy-seq (concat coll (cycle coll)))
()))
;; --- repeatedly --- ((f) throws on a non-fn; (take n …) throws on a non-number