read-string constructs sets; format %x lowercase; extend/extends? on nil

read-string/read now return real sets for #{...} literals (top-level and
nested) instead of the reader's {:jolt/type :jolt/set} form — the data
seams convert set forms to sets (recursing, preserving metadata and source
map-key order); clojure.edn already did this. The compiler keeps reading
via the raw reader, so set literals in code stay forms the analyzer lowers.

format %x now emits lowercase hex (Chez number->string is uppercase); %X
unchanged.

extend and extends? handle a nil target type (host tag "nil"), matching
extend-type — protocols can be extended to nil via the function form, not
just the macro.

Found porting transit/data.json and shaking out aero.
This commit is contained in:
Yogthos 2026-06-24 14:03:47 -04:00
parent e74b940db5
commit c26fd175f2
8 changed files with 604 additions and 534 deletions

View file

@ -383,7 +383,7 @@
;; extend-type). Tags are canonical host names or ns-qualified record names,
;; so a bare record name also matches its "ns.Name" tag.
(defn extends? [protocol atype]
(let [want (name atype)
(let [want (if (nil? atype) "nil" (name atype))
dotted (str "." want)
dlen (count dotted)]
(boolean (some (fn [t]
@ -397,14 +397,16 @@
;; pairs, methods registered under the type's (canonicalized) name — so
;; (extend 'String P {:m (fn [x] ...)}) dispatches exactly like extend-type.
(defn extend [atype & proto+mmaps]
(loop [s (seq proto+mmaps)]
(when s
(let [proto (first s)
mmap (second s)
pname (name (get proto :name))]
(doseq [[k f] mmap]
(register-method (name atype) pname (name k) f)))
(recur (nnext s)))))
;; nil extends on nil values; its host tag is the string "nil" (as extend-type).
(let [tname (if (nil? atype) "nil" (name atype))]
(loop [s (seq proto+mmaps)]
(when s
(let [proto (first s)
mmap (second s)
pname (name (get proto :name))]
(doseq [[k f] mmap]
(register-method tname pname (name k) f)))
(recur (nnext s))))))
(defmacro extend-type [tsym & body]
;; register-method is a fn (clojure.core); pass type/protocol/method NAMES as