3 ms·
I wouldn't go so far to say as there is anything wrong in closures itself, as much as a special case with regard to how it plays out in combination with the way
by trezor 16y ago
I wouldn't go so far to say as there is anything wrong in closures itself, as much as a special case with regard to how it plays out in combination with the way the iterator pattern is integrated into the language itself.
I agree that in the example provided it does seem counter-intuitive at first, but v is clearly a variable tied to the the loop and there is nothing that explicitly tells us if it is scoped outside the loop or to the code-block within the loop.
If anything, I'd say it's the implementation of the iterator pattern which is broken, not the closures themselves (which I've had zero issues with).