Why Ruby?

Jacob Carlborg doob at me.com
Sun Dec 19 07:36:14 PST 2010


On 2010-12-18 21:48, Simen kjaeraas wrote:
> bearophile <bearophileHUGS at lycos.com> wrote:
>
>> Jacob Carlborg:
>>
>>> 1 D: foo(writeln(3)); // lazy argument
>>> 1 Scala: foo(_ * _)
>>> 2 C#: foo(x => x * x);
>>> 3 Scala: foo((x) => x * x)
>>> 4 Python: foo(lambda x: x * x)
>>> 5 Ruby: foo { |bar| x * x }
>>> 5 Ruby: foo do |x| x * x end
>>> 6 D: foo((int x) { return x * x; });
>>> 7 C++1x: foo([](int x){ return x * x; });
>>> 7 Apple's (Objective)-C(++) block extension: foo(^(int x){ return x *
>>> x; });
>>> 8 JavaScript: foo(function(x){ return x * x })
>>> 9 PHP: foo(function ($x) use($fooBar) { return $x * $x; }); // "use" is
>>> used for explicitly telling what variables should be available when the
>>> scope is gone.
>>
>> (In D there are template lambdas too). This topic was discussed some
>> in past. I like a syntax similar to:
>> foo({x,y => x * y})
>> foo({int x, int y => x * y})
>
> I really like this. The curly braces clearly show it to be a new scope,
> and the syntax is concise and understandable.

I don't like it, it's not enough improvement. Compared to this 
suggestion I think the current syntax is good enough.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list