On Jan 15, 2010, at 3:26 AM, Sean Devlin wrote:

> user=> (seq [])
> nil
> 
> Why is nil returned, instead of an empty sequence?

It's fundamental to Clojure's seq abstraction that every seq has a first. There 
is no such thing as an empty seq. If you call the seq function on an empty 
collection, it can't return a seq because that (hypothetical) seq would have no 
first. Instead seq returns nil meaning "no seq".

(seq x) (used as a predicate) is the canonical way in Clojure to ensure that x 
contains at least one item.

Rich's video about Clojure sequences at iTunes and on blip.tv provides more 
details and rationale.

--Steve

-- 
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

Reply via email to