lazy thoughts

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Jan 12 09:14:16 PST 2009


Daniel Keep wrote:
> 
> 
> Andrei Alexandrescu wrote:
>> [snip]
> 
> I like the idea of lazy evaluation; heck, I toyed around with stack 
> threads so I could write generators.
> 
>> Also, lazy evaluation has the risk of getting confusing as there's a 
>> lot of escaping. Consider:
>>
>> int[] arr = [ 1, 2, 3, 4 ];
>> auto squares = map!("a * a")(arr);
>> arr[] = [ 5, 6, 7, 8 ];
>>
>> Now iterating squares will see different numbers than the original ones.
>>
>> Please let me know what you think!
>>
>> Andrei
> 
> Maybe map should only take invariant data; that way, it's fairly obvious 
> to the user that you need to pass a block of data that isn't going to be 
> changed under the map's feet.

That would reduce map's applicability considerably.

Andrei



More information about the Digitalmars-d mailing list