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
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}
By the way, FYI:
(reduce #(assoc %1 %2 %2) {} (range 10))
or
Hi,
recently I discovered the following behaviour of transient hash-maps
which seems a bit odd to me:
user (def thm (transient {}))
#'user/thm
user (dotimes [i 10]
(assoc! thm i i))
nil
user (count thm)
8
user (persistent! thm)
{0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7}
The same
On May 30, 12:32 am, Daniel Borchmann
daniel.borchm...@googlemail.com wrote:
The same happens if i goes up to 100, 1000, ... Is this a bug or is
this a fundamental misconception of mine?
You're using them wrong. Transients are not imperative data
structures. You need to capture the return
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