Why is D unpopular, redux.

Dukc ajieskola at gmail.com
Tue May 24 13:49:28 UTC 2022


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));
}
```




More information about the Digitalmars-d mailing list