Re: [Vala] Lambda expression with arguments?



Am Mittwoch, den 05.09.2007, 01:30 -0400 schrieb Michel Salim:
Hello,

All the examples on the Vala site involves using lambda expressions as
signal handlers. The expressions there take no parameters and return
void.

Getting a lambda expression to return something seems straightforward,
but how does one write a lambda expression that takes arguments? Can
the types of the parameters and return value be specified?

As the samples demonstrate arguments are passed like this:

    btn.clicked += b => {
        stdout.printf ("Click!\n");
    }

    s.notify += (s, p) => {
        stdout.printf ("Property `%s' changed\n", p.name); // [*]
    }

Return and parameter types are resolved automatically. If you really
want to specify them, you have to use a method. It's part of the concept
"Lambda Function" to omit "boring details" like typenames.


[*] Due bug 473804 currently you have to explictly cast 
    the "p" argument: ((ParamSpec)p).name

Ciao,
Mathias
-- 
Mathias Hasselmann <mathias hasselmann gmx de>
http://taschenorakel.de/

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil



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