这是indexloc提供的服务,不要输入任何密码
Skip to content

ClojureScript sorted-map does not print in sorted order for maps with more than 8 elements #645

@noahmoss

Description

@noahmoss

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:

(def us-states
  {"AK" "Alaska"
   "AL" "Alabama"
   "AR" "Arkansas"
   "AZ" "Arizona"
   "CA" "California"
   "CO" "Colorado"
   "CT" "Connecticut"
   "DE" "Delaware"
   "FL" "Florida"})

(def reverse-states
  (into (sorted-map) us-states)) 

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:

{"AK" "Alaska",
 "FL" "Florida",
 "CT" "Connecticut",
 "AR" "Arkansas",
 "AL" "Alabama",
 "CA" "California",
 "DE" "Delaware",
 "AZ" "Arizona",
 "CO" "Colorado"}

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:

  • Removing an element from the original map results in the order being retained when evaluated. It only seems to be an issue for maps with more than 8 elements.
  • Following the same steps in Clojure prints the map in sorted order, for any number of elements.
  • Creating and evaluating the map directly with (sorted-map "AK" "Alaska" ...) doesn't seem to have this issue

Would love some insight into this since it made me mistakenly believe that my code was broken for a while :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions