Hi,

On Jun 29, 6:56 am, Todd <t.greenwoodg...@gmail.com> wrote:
> Q: Why does range return a LazySeq whereas seq returns
> a ChunkedCons? I can see that these two classes are
> very different...but I don't really understand what's
> going on here.

seq returns whatever is contained in the lazy-seq:

user=> (type (lazy-seq [1 2 3]))
clojure.lang.LazySeq
user=> (type (seq (lazy-seq [1 2 3])))
clojure.lang.PersistentVector$ChunkedSeq
user=> (type (seq (lazy-seq (cons 1 nil))))
clojure.lang.PersistentList

LazySeq is a container which stores information on *how* to obtain
the next steps of the sequence. Once realised, it stores the result.

Which already points to...

> Q: Since doall walks the entire seq, it almost seems
> like the lazy seq isn't a lazy seq anymore... I mean,
> if seq'ing a LazySeq returns a different type, then
> I'd almost expect doall to return a different type,
> too. One that's not lazy.

Running through the sequence with doall will realise the contents of
the sequence. You still have a LazySeq, but the computation stored in
it is now replaced by the actual result of the computation.

> Q: So, is this the idiomatic way to convert the
> LazySeq or ChunkedCons to a Persistent (list|vector)?

For vector: (vec your-seq); for list: (list* your-seq). Although this
is not really interesting. The list will just act like the sequence.
So just calling doall is sufficient in case you have to get rid of
the laziness. If you need the properties of the vector, there is vec.

> Q: Where are the clojure.lang classes documented?
> I see the classes in the source, but they do not
> appear to have javadocs.

You should treat the underlying classes as implementation detail.

Hope this helps.

Sincerely
Meikel

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