clj-commons / potemkin

some ideas which are almost good
577 stars 53 forks source link

Question: why so many ancestors difference betwence Clj map and a PotemkinMap? #63

Closed piotr-yuxuan closed 2 years ago

piotr-yuxuan commented 3 years ago

Thank you very much for this amazing library. I wish I were as deeply knowledgeable of Clojure and I had fathomed it as deep as you!

See here for the full differences: https://github.com/piotr-yuxuan/closeable-map/blob/39eb776d8452386e9068562bcac3e41084f86ad5/README.md#technicalities.

Notably, there are:

 ;; Ancestors of Clojure map only but not a custom map.
 #{clojure.lang.AFn ; Concrete type, but see below for IFn.
   clojure.lang.APersistentMap
   clojure.lang.IEditableCollection
   clojure.lang.IKVReduce
   clojure.lang.IMapIterable
   java.io.Serializable}

 ;; Ancestors of some custom map only.
 #{clojure.lang.IType
   java.util.Iterator
   potemkin.collections.PotemkinMap
   potemkin.types.PotemkinType}
KingMob commented 2 years ago

Well, the A* ancestors are abstract classes, and potemkin's map types don't use them (could be a reason, but it could also just be due to sheer age of the library).

IKVReduce and IMapIterable are enhancements that weren't added until 2015, so they were definitely invented after potemkin's def-map-type. I just tested, and reduce-kv works on a def-map-type, so I suspect these are just optimizations.

IEditableCollection is about transient generation. I tested, and it looks like it flat out doesn't work, but it's worth a PR if you want to try adding it!