On Sunday, 16 June 2019 at 01:36:38 UTC, Timon Gehr wrote:
It's a bug. It's memory corruption. Different objects with
overlapping
lifetimes use the same memory location.
Okay. Seen that way, it is clear to me why it's a bug.
...
No, it's not the same. Python has no sensible notion of
variab
On 15.06.19 18:29, Rémy Mouëza wrote:
On Saturday, 15 June 2019 at 01:21:46 UTC, Emmanuelle wrote:
On Saturday, 15 June 2019 at 00:30:43 UTC, Adam D. Ruppe wrote:
On Saturday, 15 June 2019 at 00:24:52 UTC, Emmanuelle wrote:
Is it a compiler bug?
Yup, a very longstanding bug.
You can work ar
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 out
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 someo
On Saturday, 15 June 2019 at 01:21:46 UTC, Emmanuelle wrote:
On Saturday, 15 June 2019 at 00:30:43 UTC, Adam D. Ruppe wrote:
On Saturday, 15 June 2019 at 00:24:52 UTC, Emmanuelle wrote:
Is it a compiler bug?
Yup, a very longstanding bug.
You can work around it by wrapping it all in another l
On Saturday, 15 June 2019 at 00:30:43 UTC, Adam D. Ruppe wrote:
On Saturday, 15 June 2019 at 00:24:52 UTC, Emmanuelle wrote:
Is it a compiler bug?
Yup, a very longstanding bug.
You can work around it by wrapping it all in another layer of
function which you immediately call (which is fairly
On Saturday, 15 June 2019 at 00:24:52 UTC, Emmanuelle wrote:
Is it a compiler bug?
Yup, a very longstanding bug.
You can work around it by wrapping it all in another layer of
function which you immediately call (which is fairly common in
javascript):
funcs ~= ((x) => (int i) { nums
Take a look at this code:
---
import std.stdio;
void main()
{
alias Func = void delegate(int);
int[][] nums = new int[][5];
Func[] funcs;
foreach (x; 0 .. 5) {
funcs ~= (int i) { nums[x] ~= i; };
}
foreach (i, func; funcs) {
func(cast(int) i);
}