Algorithmic lists
Ulf Wiger
etxuwig@REDACTED
Tue Oct 17 13:29:19 CEST 2000
On Tue, 17 Oct 2000, Richard Carlsson wrote:
>
>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.
Yes, this is exactly was was intended for the lists.erl module, since
it has to be backwards compatible.
Functions that generate lazy lists would have to go into your
lazy_lists module (is it finished yet). ;)
/Uffe
>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
--
Ulf Wiger tfn: +46 8 719 81 95
Strategic Product & System Management mob: +46 70 519 81 95
Ericsson Telecom AB, Datacom Networks and IP Services
Varuvägen 9, Älvsjö, S-126 25 Stockholm, Sweden
More information about the erlang-questions
mailing list