Why Ruby?

bearophile bearophileHUGS at lycos.com
Sat Dec 18 12:01:35 PST 2010


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})

Bye,
bearophile


More information about the Digitalmars-d mailing list