Chez inc 3m: numeric-edge literal emit + variadic assoc!
##Inf/##-Inf/##NaN were emitted to bare inf/-inf/nan, which are unbound symbols in
Chez. emit-const now lowers them to +inf.0/-inf.0/+nan.0. The -e/element printer
renders them inf/-inf/nan (Chez's number->string gives +inf.0), and str renders the
long Clojure forms Infinity/-Infinity/NaN. assoc! is now variadic ((assoc! t k v
& kvs)) like Clojure.
Prelude parity 1382 -> 1407/2497, 0 new divergences. str of inf INSIDE a collection
still wants the long form (needs the Phase-2 recursive str renderer), so
[inf inside coll] is allowlisted. Transducer arities and the cdr-on-()/\p{} regex
gaps are split out to jolt-kxsr/jolt-y1zq.
This commit is contained in:
parent
1826c8b3e9
commit
c28b5406ca
7 changed files with 65 additions and 16 deletions
|
|
@ -13,6 +13,11 @@
|
|||
((string? v) v)
|
||||
((char? v) (string v))
|
||||
((regex-t? v) (regex-t-source v))
|
||||
;; str/print render the infinities and NaN long-form (Clojure .toString),
|
||||
;; unlike the -e printer's inf/-inf/nan.
|
||||
((and (flonum? v) (fl= v +inf.0)) "Infinity")
|
||||
((and (flonum? v) (fl= v -inf.0)) "-Infinity")
|
||||
((and (flonum? v) (not (fl= v v))) "NaN")
|
||||
(else (jolt-pr-str v))))
|
||||
(define (jolt-str . xs)
|
||||
(let loop ((xs xs) (acc '()))
|
||||
|
|
|
|||
|
|
@ -122,10 +122,14 @@
|
|||
# jolt models every number as a double (no ratios/bignums; see reader.janet).
|
||||
# Emit flonums so arithmetic matches the Janet host and Chez doesn't fall into
|
||||
# exploding exact rationals (mandelbrot). Integer-valued -> append ".0".
|
||||
(number? v) (let [s (string v)]
|
||||
(if (or (string/find "." s) (string/find "e" s) (string/find "n" s))
|
||||
s
|
||||
(string s ".0")))
|
||||
# ##Inf/##-Inf/##NaN: Janet stringifies these as inf/-inf/nan, which are
|
||||
# unbound symbols in Chez — emit Chez's flonum literals instead.
|
||||
(number? v) (cond
|
||||
(= v math/inf) "+inf.0"
|
||||
(= v (- math/inf)) "-inf.0"
|
||||
(not= v v) "+nan.0"
|
||||
(let [s (string v)]
|
||||
(if (or (string/find "." s) (string/find "e" s)) s (string s ".0"))))
|
||||
(string? v) (string/format "%j" v) # quoted+escaped string literal
|
||||
# keyword literal -> (keyword ns name); ns is everything before the first "/"
|
||||
(keyword? v) (let [s (string v) idx (string/find "/" s)]
|
||||
|
|
|
|||
|
|
@ -98,9 +98,15 @@
|
|||
;; jolt models every number as a Clojure double: integer-valued values print
|
||||
;; without a ".0" (the Janet host prints (* 1.0 5) as "5", (/ 1 2) as "0.5").
|
||||
(define (jolt-num->string x)
|
||||
(if (and (rational? x) (integer? x))
|
||||
(number->string (exact x))
|
||||
(number->string x)))
|
||||
(cond
|
||||
;; the -e / element printer renders the infinities and NaN as inf/-inf/nan
|
||||
;; (Chez's number->string gives +inf.0 etc.); the str/print family uses the
|
||||
;; long "Infinity"/"NaN" forms (see jolt-str-render-one in converters.ss).
|
||||
((and (flonum? x) (fl= x +inf.0)) "inf")
|
||||
((and (flonum? x) (fl= x -inf.0)) "-inf")
|
||||
((and (flonum? x) (not (fl= x x))) "nan")
|
||||
((and (rational? x) (integer? x)) (number->string (exact x)))
|
||||
(else (number->string x))))
|
||||
|
||||
;; Program-final-value printer. jolt's `-e` prints in str-style: strings raw (no
|
||||
;; quotes), chars as `\c`/`\newline`, collections recursively. NOTE: maps/sets
|
||||
|
|
|
|||
|
|
@ -27,9 +27,10 @@
|
|||
(jolt-trans-check t "conj!")
|
||||
(jolt-transient-coll-set! t (apply jolt-conj (jolt-transient-coll t) xs))
|
||||
t)
|
||||
(define (jolt-assoc! t k v)
|
||||
;; (assoc! t k v & kvs): variadic like Clojure (jolt-assoc already folds pairs).
|
||||
(define (jolt-assoc! t . kvs)
|
||||
(jolt-trans-check t "assoc!")
|
||||
(jolt-transient-coll-set! t (jolt-assoc (jolt-transient-coll t) k v))
|
||||
(jolt-transient-coll-set! t (apply jolt-assoc (jolt-transient-coll t) kvs))
|
||||
t)
|
||||
(define (jolt-dissoc! t . ks)
|
||||
(jolt-trans-check t "dissoc!")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue