Why Ruby?

Nick Sabalausky a at a.a
Thu Dec 16 14:40:08 PST 2010


"Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message 
news:iedqos$787$1 at digitalmars.com...
> On 12/16/10 1:30 PM, Jacob Carlborg wrote:
>>
>> The point here isn't that we want "a" and "b" to be replaced with "_"
>> the point is that we want to get rid of the string and have a shorter
>> and less verbose syntax for delegate literals.
>
> I understand. Using strings is witnessing the fact that we couldn't find a 
> shorter syntax that didn't have problems. That being said, it's very 
> possible there are some great ones, we just couldn't find them.
>

Any problem with the other Scala/C#-style one?:

(x, y) =>  x * y

// Lowered to:

(x, y) { return x * y; }

(Maybe that was rejected before due the the weird float operators that are 
now being ditched?)

It wouldn't be used for delegates that involve actual statements (it would 
be expression-only), but that fits with the whole point of a lambda 
expression.

Also, unlike the strings it doesn't suffer the problem of being evaluated in 
the wrong scope. For instance I think it's perfctly sensible to want a short 
lambda to be able to do something like this (pardon me if I have the syntax 
for map() wrong):

int foo(int x) { ... }
collection.map!"foo(a) + 3"();
// Or if you want proper syntax highlighting:
collection.map!q{ foo(a) + 3 }();

I think that totally fits the charter of short lambdas, but the strings just 
can't do it (at least not without turning map() into something that needs to 
be mixed in). The lowered Scala/C#-style would be able to though:

int foo(int x) { ... }
collection.map!((a) => foo(a) + 3)();
// Lowered to the messier:
collection.map!((a) { return foo(a) + 3; })();




More information about the Digitalmars-d mailing list