Lambda syntax, etc

Nick Sabalausky a at a.a
Thu Feb 5 17:24:59 PST 2009


"Christopher Wright" <dhasenan at gmail.com> wrote in message 
news:gmfsqa$311e$1 at digitalmars.com...
> Kagamin wrote:
>> Yeah, C# lambdas are the killer feature. Slick, readable, C-compatible. 
>> Anders knows his job. Let's face it: delegate literals suck a little, 
>> mixins as delegates suck a lot, the former is too verbose, the latter 
>> just sucks.
>
> C# delegates in C# 2.0 are annoying. I try not to use them. The reason:
> D:
> void foo(void delegate(int) dg);
>
> C#:
> delegate void SomeName(int i);
> void foo(SomeName dg);
>
> Does C# 3 fix this? I've seen the new syntax for defining delegates, but 
> not for using them.

C# provided my first introduction to delegates (not counting 
function-pointers in C), and that oddity actually made it harder for me to 
really wrap my head around them. Once I did though, I came around to D and 
thought "Wow! That's so simple!", and it actually helped me understand C#'s 
delegates better.

My only issue with D's delegate-declaration syntax is the semi-messy 
ordering of "return type, delegate keyword, paramaters, name". Something 
closer to following would seem much more intuitive to me:

void foo(delegate void(int) dg);
//or
void foo(void dg(int));
//or
void foo(delegate(void <- int) dg);
//etc...

Although, I realize the current way is done to be consistent with function 
definitions. But, as I mentioned in another branch of the thread, I wouldn't 
mind function definitions like this:

func foo(int <- int x) {return x+1;}
//or
func foo {(int <- int x) return x+1;}
//or
func foo {int <- int x :: return x+1;}





More information about the Digitalmars-d mailing list