How should I say it... It just didn't look "symmetrical" to me.

So, basically, there is a difference between functions returning
sequences - depending on if they are lazy or eager. Hmm...

user=> (reverse [])
nil
user=> (if (reverse []) true false)
false
user=> (if (seq (reverse [])) true false)
false

user=> (lazy-seq nil)
()
user=> (seq (lazy-seq nil))
nil
user=> (if (lazy-seq nil) true false)
true
user=> (if (seq (lazy-seq nil)) true false)
false

As long as I remember which function is lazy and which one is eager, I
should be fine then.

Just wanted to really understand it.

Thanks, Frantisek


On Feb 18, 5:58 pm, Chouser <chou...@gmail.com> wrote:
> On Wed, Feb 18, 2009 at 11:46 AM, Frantisek Sodomka <fsodo...@gmail.com> 
> wrote:
>
> > What about 'conj'? Documentation says:
> > (conj nil item) returns (item).
>
> > Currently:
> > user=> (conj nil 1)
> > (1)
> > user=> (conj () 1)
> > (1)
>
> Is there something wrong with that?  It looks right and like it
> matches the docs to me.
>
> > Idiom "conj nil" is used in 'reverse': (reduce conj nil coll)
> > Currently:
> > user=> (reverse [1 2])
> > (2 1)
> > user=> (reverse [1])
> > (1)
> > user=> (reverse [])
> > nil
>
> > It looks that now all sequence functions return () instead of nil. Is
> > 'reverse' correct?
>
> Things that return lazy seqs now return an empty lazy seq, which
> prints as (), instead of nil.  However, 'reverse' is not lazy and
> normally returns a PersistentList.  I don't know that it'd be more
> correct to return an empty PersistentList than to return nil as it
> does now.
>
> --Chouser
--~--~---------~--~----~------------~-------~--~----~
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
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