@Richard >> 1. In case coll is a LazySeq why does (seq coll) realize its first >> element? I thought seq just did a type conversion and all of list, >> vector .. etc implemented Seqable or something.
> Because seq is defined as returning nil for an empty sequence. The > only way to find that out for a lazy sequence is to realize the first > element. I'm not sure if that answers why seq should realize the first element. Even by what you say, only if I wanted to find if my LazySeq was nil should I realize its first element. My understanding of seq is - restricting some Collection type abstraction to the Sequence abstraction (but maybe my thinking is wrong). When I say (seq coll) I don't mean - 1) convert it into a sequence abstraction + 2) go and find out if the coll is empty by realizing its first element. For example suppose I've produce a lazy sequence none of whose elements are realized yet. Then I need to call an API which takes a sequence as input. I just want to give the sequence abstraction of my LazySeq by calling (seq coll), but that realizes the first element (which takes 10 mins say), even if the API were not to use my LazySeq at all (based on its needs) ! How to solve this - i.e. how do I not waste 10 mins if not needed? In fact I'm not even sure why I would need to realize the first element (completely?) (which takes 10 mins) to find out if the LazySeq is not empty ? Can you please explain this further? >> 2. Why is there no other way to determine an empty coll except (not >> (seq coll)). >user=> (empty? []) >true 1:291 user=> (source empty?) (defn empty? "Returns true if coll has no items - same as (not (seq coll)). Please use the idiom (seq x) rather than (not (empty? x))" {:added "1.0"} [coll] (not (seq coll))) nil Which brings it back to my original question. 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