On 2011-09-22 00:17, Walter Bright wrote:
I've collected a few from various languages for comparison:
D
(a,b) { return a + b; }
Ruby
->(a,b) { a + b }
C++0x
[](int a, int b) { return a + b; }
C#
(a,b) => a + b
Scala
(a:Int, b:Int) => a + b
Erlang
fun(a, b) -> a + b end.
Haskell
\a b -> a + b
Javascript
function(a,b) { return a + b; }
Clojure
# (+ % %2)
Lua
function(a,b) return a + b end
Python
lambda a,b: a + b
I vote for the Scala/C# syntax. It's worth noting there's a couple of
things going on except the syntax that I think is as equally important:
* Inferred parameter types
* Automatically return the last expression
* No need for ending with a semicolon
* One line lambdas can omit the braces
Note that Scala can infer the parameter types.
An additional question, do we want/need a new syntax for declaring
lambda/delegate types?
--
/Jacob Carlborg