-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClojureScript sorted-map
does not print in sorted order for maps with more than 8 elements
#645
Comments
BTW, the states are ordered in your first code example so I used your second code example.
What I did:
What I used:
I'm not familiar with using ClojureScript and just followed the Quick Start in the wiki. Could you share what your set-up is? |
@russtoku after connecting to a shadow-cljs nREPL server you are in a JVM environment, you can then use When I shadow select and run the code in my browser I do see this issue. My theory is that the nREPL pretty printing function isn't respecting the sorted-map for some reason in shadow-cljs but I'm unsure why. Investigating now. |
Conjure does no reformatting or sorting of the results, we're just letting CIDER / shadow-cljs do whatever pretty printing it wants to. I'm trying to work out if there's a better pprint function I can pass to the nREPL when in shadow-cljs that will respect the fact that it's a sorted-map. I suspect the CLJS layer is returning a sorted map which is read as EDN by shadow-cljs in JVM land. It loses the fact that it's a sorted map though because when you EDN roundtrip a sorted map it loses it's sorting since their textual representation is identical. I suspect any JVM nREPL talking to a shadow-cljs backed app will always lose this information. A raw shadow-cljs REPL will not because you're bypassing that JVM nREPL layer and getting the raw result out of the CLJS side (where it is still sorted). I feel like this should be a general bug more shadow-cljs + nREPL users have run into, I'm trying to find an open issue about this. |
I can reproduce this with the rebel readline nREPL CLI client. I think this is a shadow-cljs + JVM nREPL thing I'm afraid. We might have to open an upstream issue with a minimal repro, probably using the rebel readline CLI like I used since it's quite minimal. $ clojure -Ttools install-latest :lib com.github.bhauman/rebel-readline :coord '{:deps/root "rebel-readline-nrepl"}' :as nrebel
$ clojure -Tnrebel connect :port 36563 (shadow.cljs.devtools.api/nrepl-select :app)
(def us-states
{"AK" "Alaska"
"AL" "Alabama"
"AR" "Arkansas"
"AZ" "Arizona"
"CA" "California"
"CO" "Colorado"
"CT" "Connecticut"
"DE" "Delaware"
"FL" "Florida"})
(into (sorted-map) us-states)
;; => {"AK" "Alaska", "FL" "Florida", "CT" "Connecticut", "AR" "Arkansas", "AL" "Alabama", "CA" "California", "DE" "Delaware", "AZ" "Arizona", "CO" "Colorado"} Returns the unsorted map, if I prn it then it remains sorted just like in Conjure.
Probably not what you wanted to hear, but at least we're getting closer to the root cause! |
Thanks for the investigation! |
@Olical shouldn't the definition of |
That shouldn't matter, the map is parsed and then when you print it back out it can be in any order. I think for tiny maps maybe the order is preserved or something due to a Clojure optimisation under the hood. So I suppose we could shuffle it in the code, but I don't think it matters in this case. |
Hello! I'm using Conjure to work on a project with both Clojure and ClojureScript, and I've noticed a strange discrepancy in evaluating sorted maps:
In ClojureScript (with shadow-cljs), evaluating this code, and then evaluating
reverse-states
on its own, results in this output in the Conjure buffer — clearly not in sorted order:However,
(prn reverse-states)
does return a string representation with the keys in sorted order, which is why I suspect this is an issue in Conjure.Additionally:
(sorted-map "AK" "Alaska" ...)
doesn't seem to have this issueWould love some insight into this since it made me mistakenly believe that my code was broken for a while :)
The text was updated successfully, but these errors were encountered: