2010/10/21 andrei <andrei.zhabin...@gmail.com>: > > (defn test [] > (let [transient-map (transient {})] > (doseq [i (range 100)] > (conj! transient-map {i (str i)} )) > (persistent! transient-map))) > > I expect that it will produce: > > { 0 "0", 1 "1", 2 "2", ..., 99 "99"} > > but it gives only > > {0 "0", 1 "1", ..., 7 "7"} > > i.e. only first 8 elements. > Is it a bug or I do something wrong? >
See: http://clojure.org/transients "...Note in particular that transients are not designed to be bashed in-place. You must capture and use the return value in the next call." Also consider using "assoc!" and recursion: (defn test [] (loop [transient-map (transient {}) i 0] (if (< i 100) (recur (assoc! transient-map i (str i)) (inc i)) (persistent! transient-map)))) Jürgen -- 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