Hi,

On Aug 8, 6:19 pm, gary ng <garyng2...@gmail.com> wrote:

> I wrote a similar version in F# which does have the advantage of
> handling infinite input or a very long partition in the sense that I
> can still consume the first element immediately and can skip to the
> second, third group ... In a sense, the result is a lazy list of lazy
> list and if the consumer doesn't hold on to any of them, the memory
> usage is constant.

I don't think it is possible to do this. At least not in a functional
way.

Assume your first item of the resulting sequence is a lazy sequence
representing the first group. To define the rest of the sequence you
have to know the end of the first group in the input sequence. However
this can only be found by traversing the input sequence. So this must
again be some lazy sequence like a drop-while or so. But no matter how
it is directly implemented, it must retain the head of the input
sequence for traversal. So, if I traverse the first group, its items
cannot be GC'd because of the rest definition of the sequence. But the
same holds true if I skip to the second group without realising the
first one: to find the actual second group I have to realise the rest
of the sequence, which will also realise the items of the first group.

So there is no point in not realising the groups: its done anyway, no
matter what. You just introduce unnecessary laziness overhead.

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