Re: [Vala] [ANNOUNCE] Vala 0.7.6 - Compiler for the GObject type system
- From: jp0409 jippii fi
- To: vala-list gnome org
- Subject: Re: [Vala] [ANNOUNCE] Vala 0.7.6 - Compiler for the GObject type system
- Date: Fri, 18 Sep 2009 14:50:58 +0300 (EEST)
Hi,
Thanks for the great release! Great progress!!
Then the bad news ;-) The output of this one is 0. Is this correct?
JP
-----------
delegate void Func ();
Func goo () {
int a = 42;
Func f = () => stdout.printf ("%d\n", a);
a = 43;
return f;
}
void main () {
var f = goo ();
f ();
}
-----------
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
--
__
Saunalahdelta mullistava uutuus Nokia N97 ja kaiken kattava TotaaliMAX nyt ennakkomyynnissä uskomattoman
edullisesti! Paketissa puhelut ja viestit (3000 min/kpl/kk), huippunopea mobiililaajakaista sekä Nokia N97
yhdellä kk-maksulla vain 59,95 e/kk (24 kk sopimus).
Katso http://saunalahti.fi/totaalimax
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]