Yes, that makes sense that you can't make that assumption. You'd have to create something like what I was discussing above:
(defn map-indexed-transducer-base [f box-mutable inc-mutable] (fn [rf] (let [i (box-mutable -1)] (fn ([] (rf)) ([result] (rf result)) ([result input] (rf result (f (inc-mutable i) input))))))) ;; this is the version that Léo would want (defn map-indexed-transducer-single-threaded [f] (map-indexed-transducer-base f unsynchronized-mutable-long! #(unsynchronized-mutable-swap! % inc)) ;; this is the version included in clojure.core (defn map-indexed-transducer-sequentially-accessed-by-different-threads [f] (map-indexed-transducer-base f volatile! #(vswap! % inc)) ;; this works with `fold` and gives you all the indices at least, but in a nondeterministic order (defn map-indexed-transducer-concurrently-accessed-by-different-threads [f] (map-indexed-transducer-base f atom #(swap! % inc)) ; or an AtomicLong variant On Monday, April 10, 2017 at 1:06:14 PM UTC-4, Alex Miller wrote: > > > On Monday, April 10, 2017 at 11:48:41 AM UTC-5, Alexander Gunnarson wrote: >> >> Léo, I definitely agree that you can use unsynchronized mutable stateful >> transducers *as long as you can guarantee they'll be used only in >> single-threaded contexts. * >> > > Transducers included in core cannot make the assumption that they will > only be used that way. (But you may be able to guarantee that with your > own.) > > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.