On Aug 4, 4:31 pm, John Harrop <jharrop...@gmail.com> wrote:
> On Tue, Aug 4, 2009 at 1:39 PM, Rich Hickey <richhic...@gmail.com> wrote:
>
> > On Tue, Aug 4, 2009 at 1:32 PM, John Newman<john...@gmail.com> wrote:
>
> > > I'm a noob, so this is probably a dumb question but, how does this work
> > with
> > > closures? Can transients be closed over?
>
> > > Like,
>
> > >> (defn make-transient-counter [init-val]
> > >> (let [acounter (transient [init-val])]
> > >> (fn [add-val] (assoc! acounter 0 (+ add-val (nth acounter 0))))))
>
> > > Is that possible? And if so, what are the thread-safety implications (if
> > > any)?
> > > ...
> > > Oh, I just re-read the description page where Rich says,
>
> > >> Not persistent, so you can't hang onto interim values or alias
>
> > > So, would the above code throw an exception?
>
> > No, it wouldn't (currently), but there is no reason to do that. There
> > are the reference types for sharing things into unknown contexts, with
> > multithreaded semantics. Refs, atoms etc.
>
> What about things like:
>
> (persistent!
> (reduce
> (fn [x [i v]] (assoc! x i v))
> (transient (vec (repeat 0 (reduce max (map first
> coll-of-index-val-pairs)))))
> coll-of-index-val-pairs))
>
Yes, that's completely fine intended usage, as the return value of the
reducing fn becomes an argument to the next call.
> which is just the transientification of
>
Nice word - transientification.
Rich
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---