3 ms·
I don't think it's a design bug. Personally, I would prefer if for each iteration of the for loop, the variables were fresh, so that even if they were captured
by tomp 14y ago
I don't think it's a design bug. Personally, I would prefer if for each iteration of the for loop, the variables were fresh, so that even if they were captured by reference, they would be different references.
So, you would be able to do:
l = [];
for i = 1 .. 10 {
f = () -> { i += 1; }
g = () -> { return i; }
l.append({adder: f, getter: g});
}
This would also play nice with loop unrolling. If the programmer wants a variable that is shared between the iteration of the for loop, the declaration should be outside the loop.