sequence and transduce were seed natives nil on the prelude; the stateful transducer arities (take-nth/map-indexed/partition-by, overlay) drive a volatile via volatile!/vswap!/vreset!/deref, also unshimmed — so the whole (sequence xform coll) / (transduce xform f coll) surface crashed. natives-xform.ss: native volatiles (a jvol record + volatile!/vreset!/ vswap!/volatile? + a deref arm); transduce/sequence built on the existing into-xform / reduce-seq. The overlay vreset!/vswap!/volatile? drive a volatile through ref-put!/:jolt/type (tagged-table only), so they're overridden natively in post-prelude.ss. driver.janet: drain each chez pipe to EOF instead of a single ev/read. A program with a stdout side effect (newline) flushes in two writes and a lone ev/read sometimes caught only the first chunk, dropping the trailing value — an intermittent gate divergence. Now reads until the pipe closes. Prelude parity 1886 -> 1898, 0 new divergences. Floor raised to 1898.
51 lines
2.6 KiB
Scheme
51 lines
2.6 KiB
Scheme
;; volatiles + sequence / transduce (jolt-cf1q.3, jolt-xjx6) — the transducer
|
|
;; application surface.
|
|
;;
|
|
;; `sequence` and `transduce` are seed natives that were jolt-nil on the prelude.
|
|
;; The stateful transducer arities (take-nth/map-indexed/partition-by/dedupe/
|
|
;; distinct, all overlay) use volatile!/vswap!/vreset!/deref, also unshimmed — so
|
|
;; the whole (sequence xform coll) / (transduce xform f coll) surface crashed.
|
|
;;
|
|
;; Volatiles are a native mutable box (jvol) — the overlay vreset!/vswap! drive a
|
|
;; volatile through jolt.host/ref-put!+get, but a Chez volatile is a record, not a
|
|
;; tagged table, so those overlay versions are overridden natively in
|
|
;; post-prelude.ss. transduce/sequence build on the existing into-xform / reduce-
|
|
;; seq machinery (natives-seq.ss / seq.ss). Loaded after those + atoms.ss (deref).
|
|
|
|
;; --- volatiles ---------------------------------------------------------------
|
|
(define-record-type jvol (fields (mutable v)) (nongenerative chez-jvol-v1))
|
|
(define (jolt-volatile! x) (make-jvol x))
|
|
(define (jolt-vreset! vol x) (jvol-v-set! vol x) x)
|
|
(define (jolt-vswap! vol f . args)
|
|
(let ((nv (apply jolt-invoke f (jvol-v vol) args))) (jvol-v-set! vol nv) nv))
|
|
(define (jolt-volatile-pred? x) (jvol? x))
|
|
;; deref reads a volatile too (partition-all/-by transducers @-deref their box).
|
|
(define %xf-deref jolt-deref)
|
|
(set! jolt-deref (lambda (x) (if (jvol? x) (jvol-v x) (%xf-deref x))))
|
|
|
|
(def-var! "clojure.core" "volatile!" jolt-volatile!)
|
|
(def-var! "clojure.core" "deref" jolt-deref)
|
|
|
|
;; --- transduce / sequence ----------------------------------------------------
|
|
;; (transduce xform f coll) / (transduce xform f init coll): build the transformed
|
|
;; reducing fn (xform f), reduce it over coll (reduce-seq honors `reduced`), then
|
|
;; run the completion (1-arg) arity. The 3-arg init defaults to (f) — the rf's
|
|
;; 0-arity, e.g. (+) = 0, (conj) = [].
|
|
(define jolt-transduce
|
|
(case-lambda
|
|
((xform f coll) (jolt-transduce xform f (jolt-invoke f) coll))
|
|
((xform f init coll)
|
|
(let* ((xf (jolt-invoke xform f))
|
|
(res (reduce-seq xf init (jolt-seq coll))))
|
|
(jolt-invoke xf res)))))
|
|
|
|
;; (sequence coll) -> a seq; (sequence xform coll) -> coll transformed by xform.
|
|
;; Materialized eagerly through into-xform then seq'd (corpus inputs are finite; a
|
|
;; fully-lazy pull is future work). Honors reduced via into-xform/reduce-seq.
|
|
(define jolt-sequence
|
|
(case-lambda
|
|
((coll) (jolt-seq coll))
|
|
((xform coll) (jolt-seq (into-xform (jolt-vector) xform coll)))))
|
|
|
|
(def-var! "clojure.core" "transduce" jolt-transduce)
|
|
(def-var! "clojure.core" "sequence" jolt-sequence)
|