Lambda syntax, etc

Nick Sabalausky a at a.a
Wed Feb 4 21:30:01 PST 2009


"BCS" <ao at pathlink.com> wrote in message 
news:78ccfa2d39bdc8cb54edb3210678 at news.digitalmars.com...
> Reply to Bill,
>
>>> I was about to say the same thing, but I think Yigal was just mixing
>> two distinct suggestions together:
>> 1) the trailing delegates proposal (aka ruby block) and
>
> I like that
>

Then we're agreed on that part :)

>> 2) A ruby-like syntax for delegate literals : {|a,b| return a+b;}
>
> I don't like that
>

The thing I like about that is that it makes it much more clear at a glance 
that the "a,b" or "int a, int b" is associated with the code block (but 
without the problem some languages have of making it hard to distinguish 
from the block's body). For the sake of syntax-consistency I would be 
perfectly willing to allow (or even require) functions to be defined the 
same way:

int add { |int x, int y|
    return x+y;
}

Or:

// "func" used to disambiguate between function call and function 
declaration
func add { |int <- int x, int y |
    return x+y;
}

Or maybe parens instead of pipes (this is similar to K&R C, isn't it?):

int add { (int x, int y)
    return x+y;
}

Although I'm sure any of those would be prohibitively unpopular.

>
> One #1 I'd be inclined to requier that the function be defined like
>
>> void DoIt(int delegate(int) dg...)
>
> D laready has this syntax for Typesafe Variadic Functions 
> http://www.digitalmars.com/d/1.0/function.html
>

I'm not quite convinced either way on this. For what reasons do you think 
the function header should be required to indicate "this uses block syntax"? 
What's wrong with just saying "If the last arg a function takes is a 
delegate, then that delegate can optionally be specified with block 
syntax."? 





More information about the Digitalmars-d mailing list