Re: [Vala] anonymous functions



On Tue, Jul 15, 2008 at 7:20 PM, Sam Liddicott <sam liddicott com> wrote:
* Sam Liddicott wrote, On 15/07/08 10:15:
I find this notation ugly:

                notify += (s, p) => {
                        stdout.printf("property `%s' has changed!\n",
                                      p.name);
                };


Is there a reason why the => should be required?

                notify += (s, p) {
                        stdout.printf("property `%s' has changed!\n",
                                      p.name);
                };


seems a lot more natural, all that's missing is the name cos there isn't
one...

Does the => signifiy anything particular?

I don't know for sure, but my guess is that it makes parsing and parse
error recovery easier. It is also similar to the lambda expression
syntax in C#, which Vala's syntax is based on.


And in the advanced example:
http://live.gnome.org/Vala/AdvancedSample


what does the s signify in

       this.foo += s => {
           stdout.printf ("Lambda expression %s!\n", name);
       };


's' is the formal parameter of the function, just like s and p are
formal parameters in the first example. You could put parentheses
around it if you like, but you don't need to because in that case
there's only one parameter.


Thanks

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





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