Why is D unpopular, redux.
deadalnix
deadalnix at gmail.com
Tue May 24 15:27:16 UTC 2022
On Tuesday, 24 May 2022 at 15:15:13 UTC, FeepingCreature wrote:
> Javascript, yes:
>
> ```
> function foo() {
> var cb = null;
> for (var i = 0; i < 10; i++) {
> if (!cb) {
> cb = function() { console.log("Hello World " + i);
> };
> cb();
> }
> }
> cb();
> }
> foo();
> ```
> Hello World 0
> Hello World 10
Now try this and tell me how it goes:
```
function foo() {
var cb = null;
for (var i = 0; i < 10; i++) {
let n = i;
if (!cb) {
cb = function() { console.log("Hello World " + n); };
cb();
}
}
cb();
}
foo();
```
If you are capturing i and mutating it, then i is going to be
mutated at the end. It says nothing about captures.
More information about the Digitalmars-d
mailing list