On Friday, November 2, 2012 9:57:17 PM UTC+8, Christophe Grand wrote: > > Hi, > > A sequence may be (and commonly is) lazy. > Sequences on collections, strings, arrays are not lazy. Nor are those > built with cons.
So `(seq range(5))` is not lazy, and its contents (0 1 2 3 4) are evaluated as `seq` returns, right? And what makes (count a-seq) slower is that it doesn't keep track of length of itself, so be it lazy or not, we'll have to traverse it to count it. Is it so? > Some sequences even have a fast (O(1)) count (eg lists, sequences on > strings...) > However you sould assume the worst case which is a traversal of the whole > sequences -- plus if the sequence is lazy (and not yet realized) the > traversal will cause its realization. > > hth, > > Christophe > > > On Fri, Nov 2, 2012 at 1:34 PM, Satoru Logic <sator...@gmail.com<javascript:> > > wrote: > >> Hi, all. >> >> I read the following description of `sequence` in the book <Clojure >> Programming>: >> >> * Obtaining the length of a seq carries a cost. >> * The contents of sequences may be computed lazily and actually >> realized only when the value involved are accessed. >> >> So a sequence is something lazy, right? >> >> I take it that if we don't do something like `(count a-seq)`, contents of >> `a-seq` would not get realized. >> >> Then if `seq` is already "lazy", what does `lazy-seq` mean? >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@googlegroups.com<javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com <javascript:> >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en > > > > > -- > Professional: http://cgrand.net/ (fr) > On Clojure: http://clj-me.cgrand.net/ (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