Also, maps don't have an ordering, so the function is misguided by 
definition. You can use a sorted-map, if having the map's keys is very 
important to you, but generally it's just confusion that leads to wanting 
this in the first place.

If you do decide the map must be sorted in a specific order, you could use 
something like 
https://github.com/flatland/useful/blob/develop/src/flatland/useful/map.clj#L222
 to 
create a sorted map whose comparator function knows about the ordering you 
want: (into (ordering-map [:a :b :c :d]) m), for example.

On Saturday, May 11, 2013 5:41:25 PM UTC-7, Andy Fingerhut wrote:
>
> What you are attempting to do is sometimes called "bashing a transient in 
> place".  See these links for some discussion and examples:
>
>     http://clojuredocs.org/clojure_core/clojure.core/assoc!
>     http://clojuredocs.org/clojure_core/clojure.core/dissoc!
>
> Andy
>
>
>
> On Sat, May 11, 2013 at 3:51 PM, Wojciech Winogrodzki 
> <wwinog...@gmail.com<javascript:>
> > wrote:
>
>> 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 clo...@googlegroups.com<javascript:>
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com <javascript:>
>> 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+u...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
-- 
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