On Jan 15, 2010, at 4:01 AM, Stephen C. Gilardi wrote:
> On Jan 15, 2010, at 3:26 AM, Sean Devlin wrote:
>
>> user=> (seq [])
>> nil
>>
>> Why is nil returned, instead of an empty sequence?
>
> There is no such thing as an empty seq.
This was true at one time, but isn't true after the changes to Clojure that
added LazySeq.
For example:
user=> (def e (filter even? [1]))
#'user/e
user=> (type e)
clojure.lang.LazySeq ; e is a lazy seq
user=> (seq? e)
true ; e is a seq
user=> (empty? e)
true ; e is empty
user=> e
() ; e prints as an empty seq
> (seq x) (used as a predicate) is the canonical way in Clojure to ensure that
> x contains at least one item.
This is still true (and is mentioned in the doc for empty?)
user=> (seq e)
nil ; seq e is nil
--Steve
--
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