Compilation times and idiomatic D code

Stefan Koch via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 17 05:56:20 PDT 2017


On Monday, 17 July 2017 at 12:51:37 UTC, jmh530 wrote:
> On Saturday, 15 July 2017 at 15:58:12 UTC, Jonathan M Davis 
> wrote:
>>
>>     int[] a;
>>     auto b = a.map!(a => a / 2)();
>>     pragma(msg, typeof(b));
>>
>> then it prints out
>>
>>     MapResult!(__lambda1, int[])
>>
>> If you have
>>
>>     int[] a;
>>     auto b = a.map!(a => a / 2)().map!(a => a)();
>>     pragma(msg, typeof(b));
>>
>> then it prints out
>>
>>     MapResult!(__lambda2, MapResult!(__lambda1, int[]))
>>
>> If you have
>>
>>     int[] a;
>>     auto b = a.map!(a => a / 2)().map!(a => a)().filter!(a => 
>> a < 7)();
>>     pragma(msg, typeof(b));
>>
>> then it prints out
>>
>>     FilterResult!(__lambda3, MapResult!(__lambda2, 
>> MapResult!(__lambda1,
>> int[])))
>>
>
> Is there any way - theoretically - to compute typeof(b) lazily, 
> so that the information is only provided as needed?

typeof(b) is needed as soon as b is declared.
So no.
There is no point in making it lazy.


More information about the Digitalmars-d mailing list