Re:WTFPython – Understanding Python through surprising snippets
by gpderetta on Monday December 23, 2019 @11:52AM
(#21864908)
To be fair I missed the note at the end of your commend on my first read. Still, in the specific C++ example, no other capture clause is valid.
Also, python could have chosen a slightly different closure semantics and preserved sanity: instead of closing over the binding itself, it could close over each object reference separately (exactly in the same way the default parameter hack works).
> excluding the special case of low-level languages with capture clauses
Of course it works, you're specifically capturing `i` by value. It's not exactly surprising that doing things completely differently yields a different result.