I have read (doc transient), (doc assoc!) and (doc persistent!), and I
don't see what I'm missing, which is why I came here for help.
To my understanding, the first creates a transient collection, which
cannot be used in other threads, and cannot be used after converting
back to a persistent collection.
user=> (doc assoc!)
-------------------------
clojure.core/assoc!
([coll key val] [coll key val & kvs])
Alpha - subject to change.
When applied to a transient map, adds mapping of key(s) to
val(s). When applied to a transient vector, sets the val at index.
Note - index must be <= (count vector). Returns coll.
assoc!'s doc says that it adds mapping of keys to values when applied
to a map, which is what this code demonstrates.
user=> (def t (transient {}))
#'user/t
user=> (assoc! t 1 1)
#<TransientArrayMap clojure.lang.PersistentArrayMap
$TransientArrayMap@1352367>
user=> (assoc! t 2 2)
#<TransientArrayMap clojure.lang.PersistentArrayMap
$TransientArrayMap@1352367>
user=> (def p (persistent! t))
#'user/p
user=> p
{1 1, 2 2}
It says that it returns col. Does that imply that I'm supposed to hang
on to col?
On Jan 27, 3:50 pm, Kevin Downey <
redc...@gmail.com> wrote:
> Please don't use transients unless you read and understand the
> documentation.
> On Jan 27, 2012 12:41 PM, "Bill Robertson" <
billrobertso...@gmail.com>