Strange closure behaviour
Adam D. Ruppe
destructionator at gmail.com
Sat Jun 15 17:06:18 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.
I can't remember where the key fact was, but I used to agree with
you (several languages work this same way, and it makes a lot of
sense for ease of the implementation), but someone convinced me
otherwise by pointing to the language of the D spec.
I just can't find that reference right now...
It is worth noting too that the current behavior also opens up a
whole in the immutable promises; the loop variable can be passed
as immutable to the outside via a delegate, but then modified
afterward, which is unambiguously a bug.
Regardless of bug vs spec, it isn't implemented and I wouldn't
expect that to change any time soon, so it is good to just learn
the wrapper function technique :) (and it is useful in those
other languages too)
More information about the Digitalmars-d-learn
mailing list