On Mon, Oct 26, 2009 at 1:55 PM, Abhijith <abhiji...@gmail.com> wrote: > > Hello everyone, > I am having problems with destructuring in doseq. > > The function below basically takes an array of arrays as its argument > and returns a mapping of the elements to the index in the outer array. > > (use 'clojure.contrib.seq-utils) > (defn foobar [arr--of-arr] > (let [ acc (transient {}) ] > (doseq [ [i e] (indexed arr-of-arr) word e ] > (assoc! acc word (if-let [v (acc word)] (conj v i) [i]))) > (persistent! acc)))
[snip] > Either that, or doseq is not meant to be used in the above fashion. You nailed it. It's not about destructuring, it's using doseq to "bash in place" a transient collection. You won't get correct results unless you take the return value of 'assoc!' as your new collection. Even though most of the time it will return the same transient you passed in with your changes applied to it, sometimes it returns a new transient. By using doseq you're losing that returned transient and running into problems. You could try using 'reduce' instead of 'doseq' -- I think that will point you in the right direction. BTW, your example args are vectors not arrays. --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---