Chez Phase 1 (increment 3n): seq-native shims + reduced
The dominant prelude-parity crash bucket was 'apply non-procedure jolt-nil': core fns calling seed-native seq fns (core_coll.janet) that have no Chez RT shim, so var-deref returns jolt-nil. A static scan of the assembled prelude turned up 52 referenced-but-undefined clojure.core names. host/chez/natives-seq.ss shims the safe seq fns over the existing seq layer: mapcat, take-while, drop-while, partition (collection arities only — the 1-arg transducer forms are jolt-kxsr), and sort (compare default; a comparator may return a 3-way number or a boolean less-than). reduced/reduced? is a jolt-reduced record in seq.ss that reduce short-circuits on and deref unwraps, so unreduced works. identical? = jolt= (the seed's definition). Deferred list?: a Chez lazy seq and a list are both cseq, so it can't be told apart without a distinct list type — a real divergence risk. Parity 1407 -> 1467/2497, 0 new divergences. emit-test 263/263.
This commit is contained in:
parent
c28b5406ca
commit
739b219d0e
7 changed files with 183 additions and 11 deletions
|
|
@ -30,6 +30,11 @@
|
|||
(define-record-type empty-list-t (fields) (nongenerative empty-list-v1))
|
||||
(define jolt-empty-list (make-empty-list-t))
|
||||
|
||||
;; reduced (jolt-y6mv): a box a reducing fn returns to stop reduce early. The
|
||||
;; reduce machinery below unwraps it; (deref a-reduced) / unreduced also read it.
|
||||
;; reduced?/reduced are def-var!'d into clojure.core in natives-seq.ss.
|
||||
(define-record-type jolt-reduced (fields val) (nongenerative jolt-reduced-v1))
|
||||
|
||||
;; ============================================================================
|
||||
;; jolt-seq — coerce a seqable to a non-empty seq, or jolt-nil when empty
|
||||
;; ============================================================================
|
||||
|
|
@ -132,8 +137,14 @@
|
|||
(define (jolt-filter pred coll) (filter-seq pred (jolt-seq coll) #t))
|
||||
(define (jolt-remove pred coll) (filter-seq pred (jolt-seq coll) #f))
|
||||
|
||||
;; honors `reduced`: a reducing fn that returns (reduced x) stops the fold and
|
||||
;; unwraps to x (so does a reduced INIT). Checked at entry, so the value returned
|
||||
;; by the last step is unwrapped on the next turn before the seq is consulted.
|
||||
(define (reduce-seq f acc s)
|
||||
(if (jolt-nil? s) acc (reduce-seq f (jolt-invoke f acc (seq-first s)) (jolt-seq (seq-more s)))))
|
||||
(cond
|
||||
((jolt-reduced? acc) (jolt-reduced-val acc))
|
||||
((jolt-nil? s) acc)
|
||||
(else (reduce-seq f (jolt-invoke f acc (seq-first s)) (jolt-seq (seq-more s))))))
|
||||
(define jolt-reduce
|
||||
(case-lambda
|
||||
((f coll) (let ((s (jolt-seq coll)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue