Strange closure behaviour
Emmanuelle
VuLXn6DBW at PPtUm7TvV6nsw.com
Sat Jun 15 19:05:31 UTC 2019
On Saturday, 15 June 2019 at 16:29:29 UTC, Rémy Mouëza wrote:
> I don't know if we can tell this is a compiler bug. The same
> behavior happens in Python. The logic being variable `x` is
> captured by the closure. That closure's context will contain a
> pointer/reference to x. Whenever x is updated outside of the
> closure, the context still points to the modified x. Hence the
> seemingly strange behavior.
I come from Ruby, where it works as I expected, so I assumed all
languages would work like that; but then, D surprised me, and
now, Python too, and apparently a whole bunch of other languages
(which is honestly kinda disheartening since I like throwing
lambdas everywhere.)
More information about the Digitalmars-d-learn
mailing list