On 2010-12-18 23:41, Walter Bright wrote:
Jacob Carlborg wrote:
foo(x, y => x * y);
The problem with all these is what is the difference between:
{ x * y }
{ x * y; } <== note the ;
{ return x * y; }
I would say there is no difference. The delegeate would be inferred to
have the same type as the function requires.
Take this for example, "foo" is declared like this:
void foo (int delegate (int x, int y) dg);
And called like this:
foo(x, y => x * y);
Then the delegate would be inferred to be:
int delegate (int, int)
If you add a semicolon or a return in the lambda body it would be
inferred to the same type.
The C++ lambda group had the same discussions.
It may not seem like much when the code is trivial, but when it gets
more complex, having 2 or 3 different syntaxes for function bodies seems
like a confusing disaster in the making.
The point is to only use the syntax when the code is trivial, like in
the above example.
--
/Jacob Carlborg