On 6 September 2010 18:49, Robert McIntyre <r...@mit.edu> wrote:
> I thought that since into uses reduce, it would be lazy, but I was wrong.
> reduce just plows through everything with a non-lazy recursion.

Well, there's another reason in that the concept of a lazy map is
problematic. In Clojure, at any rate, either you have a map or you
don't -- it's always strict.

> Why is reduce not lazy?

The tail call in reduce is a call to itself, so it's pretty hard to
imagine a meaningful way for it to be lazy -- it only has anything to
return other than a result to a further call to reduce upon reaching
the end of the sequence being reduced. Thus, it's purpose is
fundamentally to go through the entire seq producing a single "end
product".

In contrast, a right fold's tail is a call to the reduction function
with one of the arguments being a further call to foldr, so that can
be made lazy in a sufficiently lazy language; but in Clojure, only
seqs can be lazy, so that wouldn't really work either.

Sincerely,
Michał

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