On Sun, 2012-09-02 at 23:02 -0700, Ben Wolfson wrote: > Can you say what this means (the note about take-while being called in > coll order)? > > Does it mean that it's not a guarantee of the API that the predicate > passed to take-while be called *successively* on the items in the > collection passed in?
Yes, that's what it means. Sorry I was not more clear. > I would have hoped that would be guaranteed Nevertheless, by declaring "pred must be free of side-effects", `take-while' is refusing to make that promise, among many others. > otherwise you might be forcing the computation of elements of a lazy > sequence unnecessarily, which could be expensive, even if there are no > side-effects, or (potentially, at least) raise an exception that would > otherwise not be raised. In general, you may not assume that more elements of a lazy sequence than you need will not be computed. I exempt `reductions', `iterate', and any sequences derived from those in my own practice; you may be more or less comfortable with such exemptions. user=> (first (map print [1 2 3 4])) 1234nil user=> (first (map print '(1 2 3 4))) 1nil There's some misinformation on the web about exactly how this works; I recommend reading the implementations of map, filter, and concat in core.clj to gain a better understanding of seq chunking. -- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is 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