Fix map? for a deftype implementing IPersistentMap
The deftype-is-not-a-map change (#245) gated map? on jrec-record?, so only a defrecord was map?. But a deftype that implements clojure.lang.IPersistentMap is map? on the JVM — clojure.core.cache's caches are exactly that, and its TTL factory asserts (map? base) on an LRUCache passed as the base (its suite went 1314 -> 2 errors). map? now also covers a deftype whose without/dissoc method is registered — the IPersistentMap-distinctive op a vector or set lacks. An opaque deftype (RawString) stays non-map?; a defrecord stays both. Guards added to unit.edn (jolt-side: a full IPersistentMap impl will not compile on the JVM corpus oracle).
This commit is contained in:
parent
271411b3e2
commit
3dc5de91e5
2 changed files with 13 additions and 1 deletions
|
|
@ -58,6 +58,14 @@
|
|||
(find-method-any-protocol tag "valAt")
|
||||
(find-method-any-protocol tag "cons"))))
|
||||
#t))
|
||||
;; a jrec that is map? — a record, or a deftype implementing clojure.lang
|
||||
;; .IPersistentMap (clojure.core.cache's caches do). `without` (dissoc) is the
|
||||
;; map-distinctive method: vectors/sets implement Associative/ILookup but not it.
|
||||
(define (jrec-maplike? x)
|
||||
(and (jrec? x)
|
||||
(or (jrec-record? x)
|
||||
(find-method-any-protocol (jrec-tag x) "without"))
|
||||
#t))
|
||||
(define jolt-deftype-kw (keyword "jolt" "deftype"))
|
||||
;; unique present-vs-absent sentinel for extension-map lookups (so a present nil
|
||||
;; in the extension map is distinguished from a genuine miss).
|
||||
|
|
@ -399,7 +407,7 @@
|
|||
;; deftype is not. coll? additionally covers a deftype implementing a collection
|
||||
;; interface. predicates.ss vars hold a snapshot, so re-def-var! after extending.
|
||||
(define %r-jolt-map? jolt-map?)
|
||||
(set! jolt-map? (lambda (x) (or (jrec-record? x) (%r-jolt-map? x))))
|
||||
(set! jolt-map? (lambda (x) (or (jrec-maplike? x) (%r-jolt-map? x))))
|
||||
(def-var! "clojure.core" "map?" jolt-map?)
|
||||
(def-var! "clojure.core" "coll?" (lambda (x) (or (jrec-collection? x) (jolt-coll-pred? x))))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue