Why Ruby?

Simen kjaeraas simen.kjaras at gmail.com
Sun Dec 19 03:01:28 PST 2010


Walter Bright <newshound2 at digitalmars.com> wrote:

> Simen kjaeraas wrote:
>> The problem of D's lambda syntax is it is optimized for longer
>> functions. Usually, the delegates I write are one line long. I cannot
>> see that this syntax collides with anything at the moment, but feel free
>> to enlighten me:
>>  { => 4; }
>> { a => 2*a; }
>> { a, b => a>b; }
>> { => @ + @; } // turns into { a, b => a + b; }
>>
>
> If size and simplicity of typing are critical, are those really better  
> than:
>
>    "a>b"
>
> ?

No. But often, you want to call a function in a lambda, in which case
the string version croaks. Also, it is not always possible to pass the
lambda by template alias parameter, in which case the string version is
right out the window.
As for functions taking a delegate, the {=>@+@;} syntax will not work
with overloading or template functions (nor will the other syntaxen that
elides types). It could also be that functions taking delegates are or
should be rare, and thus not worth optimizing for.

-- 
Simen


More information about the Digitalmars-d mailing list