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)) which is just the transientification of (reduce (fn [x [i v]] (assoc x i v)) (vec (repeat 0 (reduce max (map first coll-of-index-val-pairs)))) coll-of-index-val-pairs)) and converts a sparse vector into a dense one. Are sets and maps going to be transientable? Sets are often subjected to mass additions or filterings, and maps to mass additions. P.S. anyone know if gmail is ever going to fix this thing so that pagedown and shift-pagedown and pageup and shift-pageup work correctly? Shift-downarrow to trim huge amounts of quoted text gets awkward fast. I know I could use outlook or whatever but I like having access to this group, and other stuff, from any computer with what's new/read/unread staying synchronized and all the messages I ever chose to keep available to re-examine, and I don't like outlook. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---