Chez Phase 1 (increment 3f): quoted literals
Emit a :quote node by reconstructing the raw reader form as RT constructor calls: symbol -> jolt-symbol, list (array) -> jolt-list, vector (tuple) -> jolt-vector, map -> jolt-hash-map, set -> jolt-hash-set, scalars via emit-const. The runtime value of a quote is just that literal data (the interpreter returns the reader form verbatim). Quote exposed a latent seq.ss bug: empty map/filter results were jolt-nil, but Clojure's (map f []) is an empty seq, so (= () (map f [])) must be true. Return jolt-empty-list (which seqs back to nil, so it's still a valid lazy-tail terminator) instead — matching jolt-take/drop/rest/list. Prelude emit reach 334 -> 342/355. Subset probe 632 -> 664/664 compiled, 0 divergences (quote + the seq fix pull 32 corpus cases into the subset). emit-test 110/110 (added 16 quote cases). corpus.edn regenerated (the 3 malformed-catch spec rows). Full gate green.
This commit is contained in:
parent
d35783bf1b
commit
930800f9a6
6 changed files with 81 additions and 19 deletions
|
|
@ -107,11 +107,15 @@
|
|||
;; map / filter / reduce / into / remove + range / take / concat / apply
|
||||
;; ============================================================================
|
||||
(define (any-nil? seqs) (and (pair? seqs) (or (jolt-nil? (car seqs)) (any-nil? (cdr seqs)))))
|
||||
;; An EMPTY seq result is () (jolt-empty-list), NOT nil — Clojure's (map f []) is
|
||||
;; an empty seq, so (= () (map f [])) is true and (nil? (map f [])) is false.
|
||||
;; jolt-empty-list seqs back to nil, so it stays a valid lazy-tail terminator for
|
||||
;; the non-empty case (printing / seq= / reduce all walk via jolt-seq).
|
||||
(define (map-seq f s)
|
||||
(if (jolt-nil? s) jolt-nil
|
||||
(if (jolt-nil? s) jolt-empty-list
|
||||
(cseq-lazy (jolt-invoke f (seq-first s)) (lambda () (map-seq f (jolt-seq (seq-more s)))))))
|
||||
(define (map-seq* f seqs) ; multi-collection map; stops at the shortest
|
||||
(if (any-nil? seqs) jolt-nil
|
||||
(if (any-nil? seqs) jolt-empty-list
|
||||
(cseq-lazy (apply jolt-invoke f (map seq-first seqs))
|
||||
(lambda () (map-seq* f (map (lambda (s) (jolt-seq (seq-more s))) seqs))))))
|
||||
(define (jolt-map f . colls)
|
||||
|
|
@ -121,7 +125,7 @@
|
|||
|
||||
(define (filter-seq pred s keep)
|
||||
(let loop ((s s))
|
||||
(cond ((jolt-nil? s) jolt-nil)
|
||||
(cond ((jolt-nil? s) jolt-empty-list) ; empty result is () (see map-seq)
|
||||
((eq? keep (jolt-truthy? (jolt-invoke pred (seq-first s))))
|
||||
(cseq-lazy (seq-first s) (lambda () (filter-seq pred (jolt-seq (seq-more s)) keep))))
|
||||
(else (loop (jolt-seq (seq-more s)))))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue