clr

souenzzo 2024-07-22T22:28:49.838189Z

Hello David. I have read your writings about porting clojure datastructure to CLR/CLRnext Last week I discovered a new behavior about clojure literals/datastructure. Maybe you are interested in checking this behavior: https://github.com/babashka/sci/issues/923

dmiller 2024-07-23T01:31:40.314329Z

That issue deals with sets, which I haven't gotten to yet, but the same behavior is true for duplicate hashmap keys. I checked the code and the code for sets parallels that for hashmaps. The SetReader class is used by the lisp reader to parse sets using the #{...} syntax. It constructs the set by calling PersistentHashSet.createWithCheck`. The check in this case is for duplicate entries. (For hashmaps, the check is for duplicate keys. I'm not sure where this behavior is documented. I don't see it on the reader doc (https://clojure.org/reference/reader). The CLJS documentation does mention it: https://cljs.github.io/api/syntax/set And there is a reference here in https://clojure.org/guides/weird_characters, but this seems like a pretty obscure location for the only mention. And the same page does not mention the restriction on hashmap keys. If you are historically curious, this was mentioned on the design pages back in 2012. https://archive.clojure.org/design-wiki/display/design/Allow%2Bduplicate%2Bmap%2Bkeys%2Band%2Bset%2Belements.html It does have recommendation to document this behavior in map/set literals. There was a JIRA issue for it: https://clojure.atlassian.net/jira/software/c/projects/CLJ/issues/CLJ-1065 But the changes addressed in the issue are only to calls to functions hash-map, hash-set, etc., not anything involving reader documentation. See also https://clojureverse.org/t/eliminating-duplicate-keys-in-an-edn-file/2968 from 2018-19. Perhaps something (lack of documentation) you'd like to bring up over on http://ask.clojure.org?