bearophile <[email protected]> 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. -- Simen
