Why Ruby?

JRM a at b.com
Sat Dec 18 11:03:03 PST 2010


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.

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.


More information about the Digitalmars-d mailing list