On Mon, 07 Dec 2009 16:51:29 +0300, Michal Minich <michal.min...@gmail.com> wrote:

Hello Denis,

1. auto t = new Thread ( { a=42 } );
or auto t = new Thread ( () { a=42 } );
It already works, just try it (but don't forget to put a semicolon at
the  end).

2. array.findAll (arr, (item) { item.contains ("abc") } ); 3. foo (
(a, b) { a + b } );
 4. array.findAll (arr, (item) { return item.contains ("abc"); } );
 I'm not proposing this syntax (maybe I probably should, but I have
feeling I would not be first). It may not even be possible to parse
it,  but seems to me more similar to how currently functions are
written. In  this setting {exp} or {stm} is not *special* case.

I believe it would work. And yes, it was already proposed by many
others.


it works with two differences:

1. the semicolon is required, even if the body consist only of one expression. This is a minor detail. 2. more importantly - parameter types must be specified explicitly. I don't understand why type of b cannot be inferred in this example:

void foo (void delegate (int a) dg)
{
    dg(1);
}

void main ()
{
    foo ( (int b)  { writeln (b); } );
}

Does the type inference has problem with template code or some other combination of features...?



It complicates semantic pass quite significantly: you can't semantically analyze delegate until you analyze "foo". It also can't infer arguments types in some cases:

void foo(T)(void delegate(T) dg);
foo( (a) { a.bar(); } );

Although I believe it is implementable and worth the trouble, there is a little gain in this feature and that's probably why it is low in the list. I think that Walter will give a green light if someone implements the feature and provides a complete patch.

Any volunteers?

Reply via email to