Lazy lists - an implementation.

Robert Virding rv@REDACTED
Wed Oct 18 12:14:11 CEST 2000


Richard Carlsson <richardc@REDACTED> writes:
>
... Lots on lazy lists and a lazy list package.
>

I think that doing it as you have done making lazy lists as

	LazyList :: () -> [] | [term() | LazyList]

makes things much simpler and more consistent.

However you still have the major problem that it is not integrated with 
the rest of the whole system (Erlang, OTP and apps).  This restricts 
what you can do with it, as the rest of the system sees this as funs 
not lists.

As Sean Hinde points out if you already have the big list then why 
bother?

Unfortunately it would not directly help Ulf Wiger either as the large
lists are generated by calls which generate "proper" lists. To use it
you would have to write new interface functions to generate the lazy 
lists and force people to use the lazy libraries.  This would still 
mean you would have to go through code and modify it, as you would 
using th existing "lazy" interface to ETS tables.

Most importantly it can't be used in patterns!!!

As it can't be used interchangably with lists, or even list patterns,
wouldn't it be better to drop the list terminology and instead call them
something else, lazy sequences?  This would help to lessen confusion.  
I wouldn't even construct them with lists, use a tagged tuple instead.  
I know it takes more space but I am only looking a one element at a 
time so it isn't really important.  This would help to remove a lot of 
errors where people inadvertantly used "normal" list operations on them 
which could generate very random errors.  And no way that I or anyone 
else would prefix their list procesing functions with a special clause! 
:-)

func(LazyList, ...) when function(LazyList) -> func(LazyList(), ...);

In short if you want to implement a "lazy" sequence be extremely 
explicit and not try to make look like lists, which they are not and 
don't behave as.

Anyway without rewriting the result of an evaluation you can create an 
aweful amount of extra work.  Also you could have fun code like

    L1 = eval(LazyList),
    L2 = eval(LazyList),

and L1 /= L2.

	Robert

-- 
Robert Virding                          Tel: +46 (0)8 545 55 017
Alteon Web Systems                      Email: rv@REDACTED
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