[Vala] Newbie help needed for Vala delegates/lambda expressions



Hi,

After programming for a long time with C/C++, I am trying to get 
comfortable with Vala for my GUI programming.

I quite like the language, but am thwarted in quickly coming to terms 
with Vala because of the absence of documentation. A particular sticking 
point right now is lambda expressions.

Here are 2 delegates I set up to add a couple of integers :

delegate int _dg_add(int a);

_dg_add f_add(int a)
{
        return (b) => a + b;
}

delegate int _dg_add2(int a, int b);

_dg_add2 f_add2(int a, int b)
{
        return () => a + b;
}

When I invoke these functions from main(), the first one works but the 
second does not :

int a = 6, b = 7;
        
int c1 = f_add(a)(b);
int c2 = f_add2(a, b);  //Problem here

The compiler gives me the message : error: Assignment: Cannot convert 
from `_dg_add2' to `int'. But then, a similar conversion was reached 
successfully with the first call to f_add

So what is wrong with my understanding ? Thanks for any help.
Manish Jain



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]