Re: Boxed math in transducers
Sorry- that should read "a little better", not "little better" ;-) -- 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.
Re: Boxed math in transducers
Hey Alex, Not sure I follow. If we deref (volatile! 5), the dereffed val is a number. `(inc @(volatile! 5))` will involve boxed math but `(inc ^long @(volatile! 5))` won't. So, for example: (defn core-take ; As in clojure.core ([n] (fn [rf] (let [nv (volatile! n)] (fn ([] (rf)) ([result] (rf result)) ([result input] (let [n @nv nn (vswap! nv dec) result (if (pos? n) (rf result input) result)] (if (not (pos? nn)) (ensure-reduced result) result (defn new-take ; Without boxed math ([^long n] (fn [rf] (let [nv (volatile! n)] (fn ([] (rf)) ([result] (rf result)) ([result input] (let [^long n @nv ^long nn (vswap! nv #(dec ^long %)) result (if (pos? n) (rf result input) result)] (if (not (pos? nn)) (ensure-reduced result) result Timing on the latter is little better. Does that make sense, or am I missing something? -- 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.
Re: Boxed math in transducers
Given that the counter is held in a volatile (boxed) object, I don't think a hint would help. On Wednesday, September 23, 2015 at 1:14:39 AM UTC-5, Peter Taoussanis wrote: > > Hi all, > > Just noticed some use of boxed math in a couple of the Clojure 1.7 > transducers (e.g. `take`). Would there be interest in a PR to add some > numerical type hints? > > Cheers :-) > -- 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.
Boxed math in transducers
Hi all, Just noticed some use of boxed math in a couple of the Clojure 1.7 transducers (e.g. `take`). Would there be interest in a PR to add some numerical type hints? Cheers :-) -- 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.