Why is D unpopular, redux.

deadalnix deadalnix at gmail.com
Tue May 24 14:41:11 UTC 2022


On Tuesday, 24 May 2022 at 13:49:28 UTC, Dukc wrote:
> On Tuesday, 24 May 2022 at 13:34:07 UTC, deadalnix wrote:
>> On Tuesday, 24 May 2022 at 07:58:13 UTC, FeepingCreature wrote:
>>> This is a bit of a controversial topic. Personally I agree 
>>> that there should be a closure allocated every loop pass, but 
>>> *every other language* allocates them for the whole 
>>> stackframe, so...
>>
>> That is patently false. Javascript? C#?
>
> I do recall that C# has the same problem. Or at least had in 
> Unity, ~6 years ago. I work around it this way (pseudocode, 
> didn't test this):
>
> ```D
> foreach (i; 0..10)
> { auto makeDelegate(size_t closureVar)
>   { return ()
>     { // closureVar is i, but will be different for each 
> iteration
>     };
>   };
>
>   doSomethingWithDelegate(makeDelegate(i));
> }
> ```

This was fixed in C#5, in 2012, so 10 years ago.


More information about the Digitalmars-d mailing list