[Vala] Confusing closure behavior
- From: Vivien Kraus <vivien planete-kraus eu>
- To: vala-list <vala-list gnome org>
- Subject: [Vala] Confusing closure behavior
- Date: Tue, 09 Apr 2019 00:00:50 +0200
Hello,
I have come across this weird closure thing. In other programming
languages, I would expect the closure in t to have a copy of i, but it
only has a reference. Is it expected?
Best regards,
Vivien
public delegate void Thunk();
public static void run (Thunk t) {
t ();
}
int main() {
int i = 0;
Thunk t = () => {
stdout.printf ("%d = 0, right?\n", i);
};
i = 1;
run (t);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]