[has demo] Can't seem to make a sorted map of 12 items... can you help?

Here is a reproducible demo of my issue: Sorted Map Stops Working After X Size

I’m not sure why I can’t sort a map of 12 items… Do you know why? Is there a way to sort them into a sorted-map?

I tried what you did in a plain Clojure REPL started from the command line on a macOS system, and the result of the (into (sorted-map) …) calls printed with the integer keys sorted as I would expect. I tried it both with and without the compliment dependency you are using, and I got a correctly sorted map both times.

Are you perhaps using some technique of showing the maps in some IDE environment, that might be changing the sorted map back into an unsorted map before displaying it?

You can try converting printing the sorted map into a string with something like (pr-str (into (sorted-map) @maps3))). If that shows a string with the keys sorted in order, then the sorted map is working fine.

1 Like

Could not reproduce from the repl, running via cider.

 (into (sorted-map) @maps2)
{100 {:banana :tree},
 105 {:bunny :tree},
 110 {:banana :butterfly},
 200 {:banana :bunny},
 225 {:banana :banana},
 300 {:banana :frog},
 360 {:butterfly :tree},
 400 {:frog :tree},
 410 {:banana :butterfly},
 505 {:bunny :tree},
 525 {:banana :banana},
 660 {:butterfly :tree}}

(into (sorted-map) @maps3)
{100 {:banana :tree},
 105 {:bunny :tree},
 110 {:banana :butterfly},
 200 {:banana :bunny},
 225 {:banana :banana},
 300 {:banana :frog},
 360 {:butterfly :tree},
 400 {:frog :tree},
 410 {:banana :butterfly},
 505 {:bunny :tree},
 525 {:banana :banana},
 660 {:butterfly :tree}}
1 Like

Thank you very much. I will continue to investigate the cause/source of this unusual behavior.

Are you perhaps using some technique of showing the maps in some IDE environment, that might be changing the sorted map back into an unsorted map before displaying it?

This may very well be the reason, though I am not sure why or what is causing it currently.

Thank you very much for testing and finding the (ir)reproducibility. I will make a habit to test locally on my own machine in the future first before posting something I have written on an online IDE.

Might be a nice case for NextJournal to look at if they are the only platform manifesting this. I don’t recall folks having problems with that platform, seems pretty solid. I think @andy.fingerhut is probably close with his theory.

1 Like

I will ask the nice folks at Nextjournal about it :+1:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.