clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
camsaul 2021-06-18T03:01:13.089900Z

@seancorfield why not just have your custom map type normalize the keys coming in, and implement equiv so it considers itself equal to a plain Clojure map that would otherwise be the same if its keys were normalized? I implemented a lisp-case/`snake_case` insensitive map a while back for a project I'm working on and that's finally the behavior I settled on. This way I don't have to update any old tests and things like select-keys still mostly do the right thing

seancorfield 2021-06-18T03:04:29.091Z

@camsaul As I said: this is “for non-Clojure language interop reasons”. It has to work as a hash map in the non-Clojure code too and that requires access via UPPERCASE STRINGS.

camsaul 2021-06-18T03:13:26.097100Z

Maybe you could make the key behavior switchable and do something like (uppercase-keys-map my-map) in the Java interop code? Not an ideal solution but not sure one really exists

seancorfield 2021-06-18T03:16:10.097400Z

Aside from select-keys pulling the rug out from under me, what we’ve got works great, and has done for years as we slowly rewrite all that legacy code in Clojure 🙂

seancorfield 2021-06-18T03:16:27.097600Z

So, eventually, I won’t have to care about this funky hash map type!

👍 1
seancorfield 2021-06-18T03:19:22.097900Z

It took me quite a while to arrive at a data structure that would round-trip between the legacy host language and the embedded Clojure code (invoked via the Java API). select-keys is the only thing that trips me up from time-to-time. Everything else “just works” so it looks like a case insensitive hash map to the host language (uppercase string keys) and like a regular Clojure map with keyword keys and almost every operation in both languages preserves the illusion.

seancorfield 2021-06-18T03:20:29.098100Z

The host language is ColdFusion/CFML (running on the JVM) in case you’re wondering… 🙂

camsaul 2021-06-18T03:26:13.100100Z

Maybe a bad idea, but why not just intern a version of select-keys that fixes the bug? Not something you should do all time but I think in exceptional circumstances you might want to do something like that

seancorfield 2021-06-18T03:39:34.100300Z

That is slightly tempting (but probably a bad idea 🙂 ).