Why Ruby?

Stephan Soller stephan.soller at helionweb.de
Wed Dec 15 07:02:19 PST 2010


On 14.12.2010 19:49, Simen kjaeraas wrote:
> Stephan Soller <stephan.soller at helionweb.de> wrote:
>
>> [1, 2, 3, 4, 5].select((int e){ return e > 3; })
>> .collect((int e){ return e*e; });
>>
>> It's already fairly compact. The main overhead is the parameter type
>> and the return statement. I don't believe this can be reduced any more
>> without breaking consistency of the language.
>
> The delegates can be passed by alias parameter, and then be written
> without the parameter type:
>
> @property void bar(alias t)() {
> t(3);
> }
>
> void main() {
> bar!((e){writeln(e);});
> }
>

Hm, nice trick, thanks Simen. Looks interesting and more general to use. 
Will try that for my next D project.

Happy programming
Stephan Soller


More information about the Digitalmars-d mailing list