Re: [Vala] Confusing closure behavior
- From: Vivien Kraus <vivien planete-kraus eu>
- To: vala-list <vala-list gnome org>
- Subject: Re: [Vala] Confusing closure behavior
- Date: Tue, 09 Apr 2019 08:25:31 +0200
Digging a little deeper, I have some more confusion. This makes the
for-loop and the foreach-loop behave differently. What do you think of:
// capturing the for variable should capture a copy if the variable is
// local to the for loop
public delegate void Thunk();
int main() {
Thunk thunk = () => {};
for (int i = 0; i < 1; i++) {
thunk = () => {
stderr.printf ("%d = 0, right?\n", i);
};
}
thunk ();
int[] indices = { 0 };
foreach (var i in indices) {
thunk = () => {
stderr.printf ("%d = 0, right?\n", i);
};
}
thunk ();
return 0;
}
Confusingly,
Vivien
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]