Clojure 1.5.1.

I'm trying to reorder a map. The keys in the map are known beforehand and 
their order is undefined. So, I'm taking this map and construct a new 
transient map with the keys ordered as I need them:

defn reorder-map []
      (let [
            m {:j 10 :g 7 :b 2 :d 4 :e 5 :h 8 :i 9 :f 6 :c 3 :a 1 }
            kwds [:a :b :c :d :e :f :g :h :i :j]
            temp (transient {})
            ]
        (doseq [k kwds]
          (assoc! temp k (m k)))
        (persistent! temp)))

It returns {:a 1, :b 2, :c 3, :d 4, :e 5, :f 6, :g 7, :h 8}. The order is 
as I have defined, but there are *only 8 out of 10 items* in the new map.

If I do the same with an atom, all items are taken into account, but the 
order is not as expected:

(defn reorder-map-2 []
      (let [
            a (atom {})
            m {:j 10 :g 7 :b 2 :d 4 :e 5 :h 8 :i 9 :f 6 :c 3 :a 1 }
            kwds [:a :b :c :d :e :f :g :h :i :j]
            ]
        (doseq [k kwds]
          (swap!  a assoc k (m k)))
        @a))

It returns {:a 1, :c 3, :b 2, :f 6, :g 7, :d 4, :e 5, :j 10, :i 9, :h 8}

I don't know the internals to judge in which order items are associated in 
a map. It seems that normal association prepends; transient association 
appends; atom association does not obey any particular order.

Anyway,* it seems to be a bug in that the transient didn't accept more than 
8 items*. It should, I suppose.

Or am I doing sth. very wrong?

Thank you -






-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to