Re: [Vala] [ANNOUNCE] Vala 0.7.6 - Compiler for the GObject type system
- From: Jürg Billeter <j bitron ch>
- To: Frederik <scumm_fredo gmx net>
- Cc: vala-list gnome org
- Subject: Re: [Vala] [ANNOUNCE] Vala 0.7.6 - Compiler for the GObject type system
- Date: Fri, 18 Sep 2009 13:03:31 +0200
On Fri, 2009-09-18 at 10:11 +0200, Frederik wrote:
Great release!
Thanks.
One question about closures: is it intentional that captured variables
change after the closure? For example:
------------------------------------------------------
delegate void Func ();
void main () {
int a = 42;
Func f = () => stdout.printf ("%d\n", a);
a = 43;
f ();
}
------------------------------------------------------
Output: 43
This is correct, there is only one instance of the variable `a' and that
instance is captured by the closure. You can also change the value of
`a' inside the closure and this will affect the outer method as well as
there is only one instance of this variable.
This seems to affect currying as well:
------------------------------------------------------
delegate int IntFuncInt (int i);
IntFuncInt curried_add (int a) {
return b => a + b;
}
void main () {
int a = 3;
int b = 4;
stdout.printf ("%d + %d = %d\n", a, b, curried_add (a)(b));
}
------------------------------------------------------
Output: 3 + 4 = 4
This was a bug in how delegates were returned from methods. This is now
fixed in master.
Jürg
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]