> Francis, thanks for separating out the different types of intermediate > collections. I'm not entirely clear on type 1. It sounds like those are > just collections that are already there before processing them. Or are you > saying that Clojure has to convert them to a seq as such? Why would doseq > have to do that, for example?
There are two abstractions for working over a collection in clojure: sequences (i.e. Something that implements first and rest) and reducibles (something that implements IReduce or CollReduce). Some functions use sequences as their basic interface to a collection: this includes map, doseq, etc (all the "traditional" clojure functions). Anything that calls first, rest, next, or seq during its operation (including most hand-rolled loop-recurs!) is using sequences. If the type is not already a sequence, then a sequence object needs to be created over it which knows how to walk it. This is an extra intermediate collection. What precisely happens depends on the input type, but it almost always involves additional object allocations. For efficiency Other functions use reduction as their abstraction via IReduce, which allows a collection to reduce over itself. This is generally much more efficient because the type can walk over its own internal structures efficiently and does not need to provide the laziness or immutability guarantees of sequences: it can use (invisible) mutation internally. But you lose control over the "pace" of the reduction: you can't pause it in the middle or access any specific item. Finally, Java has an Iterator interface, which is not used much in clojure because it is mutable. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
