Algorithmic lists

Richard Carlsson <>
Tue Oct 17 13:15:15 CEST 2000


On Tue, 17 Oct 2000, Ulf Wiger wrote:

> OK, since noone complained too much, here's a hack of lists.erl,
> where most functions have been enhanced to operate on both eager
> and lazy lists.

Well, your hacked functions give correct output, but do they behave as you
intented? They are all eager, in that if you apply your new `map' on a
lazy list, it forces evaluation of the whole list.

A more generally useful implementation would return a new lazy list, where
the `map' operation is not performed on any element until that element is
requested. Then you can create a list like the following:

		lazy_lists:map(fun (X) -> X * 2 end,
		               lazy_lists:natural_numbers())

(the list of all even nonnegative numbers) and then pass the result to
another function, which can pick as many elements from the list as it
wants, or none at all.

	/Richard Carlsson


Richard Carlsson ()   (This space intentionally left blank.)
E-mail: 	WWW: http://www.csd.uu.se/~richardc/




More information about the erlang-questions mailing list