Lazy lists - an implementation.

Robert Virding <>
Wed Oct 18 13:25:50 CEST 2000


Richard Carlsson <> writes:
>
>On Tue, 17 Oct 2000, Sean Hinde wrote:
>
>> If we already have a large list and want to generate another I guess
>> there would there be no benefit of converting this into a lazy_list
>> first? (would this make a Huge fun?)
>
>Not "Huge" - the function "lazy(L)" takes your normal list and embeds it
>in a small fun (no copying done) which will on demand return the next
>element. The space usage is comparable to a tuple with a small number of
>elements.

Yes, but you would still already have created the original huge list.
Converting it to a lazy list AFTERWARDS will not gain you anything in
space, actually it will cost you as you replace a cons cell with a 
tuple of a few extra elements.  That added to the extra execution cost 
of first making it lazy and then extracting each cons cell makes it all 
seem like a big lose.

This means that using lazy lists is really only practical if you use it 
consistently from start to finnish with an object.  That is why I 
suggested not calling them lazy lists but lazy <something else> as they 
aren't interchangeable.

	Robert

-- 
Robert Virding                          Tel: +46 (0)8 545 55 017
Alteon Web Systems                      Email: 
S:t Eriksgatan 44                       WWW: http://www.bluetail.com/~rv
SE-112 34 Stockholm, SWEDEN
"Folk säger att jag inte bryr mig om någonting, men det skiter jag i".





More information about the erlang-questions mailing list