On Sat, May 29, 2010 at 08:52:59PM -0700, ataggart wrote: > Yup, you need to use the transient functions, e.g., assoc!, just as > you would the persistent functions. This is nice since you can write > your code in the persistent style, then if you need to make some > performance tweaks, simply add some exclamation points; the structure > of the code remains the same. > > As for why you see what you're seeing, the assoc! does generally > mutate the passed in map, thus you see some map entries. The rub is > that assoc! is smart enough to choose the right implementation for the > size; for small maps (0-8 entries) an array-map is used (and the {} > literal is also an array-map). Once you assoc! the 9th element, the > function instead returns a hashmap, thus no longer mutating the > instance referenced by thm. Ah, yes:
user> (loop [thm (transient {}), i 0] (if (<= 10 i) (persistent! thm) (recur (assoc! thm i i) (inc i)))) {0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9} So, a fundamental misconception of mine then ;) Thanks! Daniel -- 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