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

_______________________________________________
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to