Please don't use transients unless you read and understand the documentation. On Jan 27, 2012 12:41 PM, "Bill Robertson" <billrobertso...@gmail.com> wrote:
> I don't understand why the two functions below (recurs and transi) do > not produce the same result. To the best of my understanding doseq > will consume an entire sequence as demonstrated here: > > user=> (doseq [x (range 0 10)] (print x)) > 0123456789nil > > user=> *clojure-version* > {:major 1, :minor 3, :incremental 0, :qualifier nil} > > user=> (defn recurs [dest src] > (if-let [element (first src)] > (recur (assoc dest element element) (rest src)) > dest)) > #'user/recurs > user=> (count (recurs {} (range 0 20000))) > 20000 > > user=> (defn transi [dest src] > (let [temp (transient dest)] > (doseq [x src] > (assoc! temp x x)) > (persistent! temp))) > #'user/transi > user=> (count (transi {} (range 0 20000))) > 8 > user=> (count (transi {} (range 0 20))) > 8 > user=> (count (transi {} (range 0 8))) > 8 > user=> (count (transi {} (range 0 7))) > 7 > > Any ideas about why the first function does not behave the same as the > second? > > Thanks > > -- > 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 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