lazy thoughts

bearophile bearophileHUGS at lycos.com
Mon Jan 12 09:44:59 PST 2009


Andrei Alexandrescu:
> I'm gearing up for changing std.algorithm, and I am thinking of making 
> the major change of favoring lazy evaluation throughout. For example, 
> consider the map function. Right now map allocates and returns a new 
> vector, for example:
[...]
> int[] arr = [ 1, 2, 3, 4 ];
> auto squares = eager(map!("a * a")(arr));
> assert(squares == [ 1, 4, 9, 16 ]);

As I have told you in the past, it's good for D to embrace more lazy operations, so I agree with this. For example from the string module of my dlibs you can see how many times xsplit() is faster than split().
In my dlibs I have map/xmap, filter/xfilter, etc, etc. The x denotes the lazy versions. So I keep both versions, and I think this is the good.
In my libs the eager() is named array() that I think is a better name, and I presume will lead to less typos.
The implementation of array() is quite reliable and efficient, so you may take a look at it.

Bye,
bearophile



More information about the Digitalmars-d mailing list