On 2010-12-18 20:03, JRM wrote:
On Sat, 18 Dec 2010 19:09:24 +0100, Jacob Carlborg wrote:

I would like a syntax that is a combination of D's lazy argument syntax
and C#'s lambda syntax. Basically like this:

If the lambda doesn't take have any parameters then you can just put the
expression between then the parentheses in the function call:

foo(writeln(3));

If the lambda have one parameter then the following syntax is used:

foo(x =>  x * x);

If the lambda takes more then one parameter then you have to use
parentheses around the lambda parameters like this:

foo((x, y) =>  x * y);

Actually if it would be possible to skip the parentheses when the lambda
take more than one argument I would be more happy with that:

foo(x, y =>  x * y);

Why not define numbered placeholders to avoid the need for named
arguments altogether.

Well, I can't think of all the syntaxes there possible can be :)

foo(@1 * @2);

//lowers to

foo((arg1, arg2) { return arg1 * arg2; });

It would be a fairly simple extension to the lazy argument syntax, and
cover most of the typical uses for short lambdas.

That doesn't look too bad, maybe somewhat confusing with numbers in the names? And it might also be could to have a way to name the arguments yourself.

--
/Jacob Carlborg

Reply via email to