assoc! fills nil for a trailing lone key (JVM parity)
JVM assoc! is variadic: with a complete first pair present (>=3 kvs), a trailing
lone key fills nil ((assoc! t :a 1 :b) => {:a 1 :b nil}); a lone key alone (1 kv)
is still a wrong-arity throw. jolt delegated to the strict persistent assoc which
threw on any odd count. Pad a trailing nil for odd kvs >=3. Corpus 2688->2690.
This commit is contained in:
parent
c788e86f1a
commit
e7f5bcb58d
2 changed files with 9 additions and 3 deletions
|
|
@ -38,7 +38,13 @@
|
|||
;; (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 (apply jolt-assoc (jolt-transient-coll t) kvs))
|
||||
;; JVM assoc! is variadic: once a complete first key/val pair is present (>=3
|
||||
;; kvs), a TRAILING lone key fills nil; a lone key alone (1 kv) is a wrong-arity
|
||||
;; throw (so don't pad it — the persistent assoc raises on odd args).
|
||||
(let ((kvs (if (and (>= (length kvs) 3) (odd? (length kvs)))
|
||||
(append kvs (list jolt-nil))
|
||||
kvs)))
|
||||
(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