Lambda syntax, etc

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Feb 5 06:17:32 PST 2009


Kagamin wrote:
> bearophile Wrote:
> 
>> C#2 has lambdas, and C#3 adds closures and more type inferencing, so C#3+ supports the following syntaxes:
>> (int i) => { return i % 3 == 1; } // C#2
>> i => i % 3 == 1 // C#3
>> i => { return i % 3 == 1; } // C#3, with statements too
>> To define a delegate o delegate closure:
>> Func<int> foo = i => { return i % 3 == 1; };
>> Func<int> foo = i => i % 3 == 1;
>> Func<int> bar = () => 2;
>> But this isn't allowed:
>> Func<void> bar = () => 2;
> 
> Yeah, C# lambdas are the killer feature. Slick, readable, C-compatible. Anders knows his job.

Without knowing the person, I disagree you could infer that from C#. 
What I see above is a smörgåsbord of syntaxes that shoot all over the 
proverbial barn door in the hope that one of them would strike someone's 
fancy. That strikes me as a rather lousily done job. Also, it is my 
perception (and not only mine) that C#'s creator completely missed the 
power of templates and generative programming.

> Let's face it: delegate literals suck a little, mixins as delegates suck a lot, the former is too verbose, the latter just sucks.

The logic doesn't quite ring, but passons :o). For what it's worth 
Walter has got positive feedback left and right from his talk discussing 
the matter. A simplification in defining function literals is being 
discussed (omitting the type from the parameters) that would simplify 
template definitions considerably. Beyond that, I don't feel that 
changes like moving the parameters on one side or the other of "{" would 
be Earth-shattering.


Andrei



More information about the Digitalmars-d mailing list