On 2011-09-22 08:47, Max Klyga wrote:
Actually Scala doesn't need type declarations in labmda literals. Most
of the time argument types are infered. It would be awesome if D infered
argument types for labdas too.
Also Java 8 adopted the same lambda syntax as Scala and C#.
To add a few things to your list:
Nemerle
fun (x, y) { x + y }
(x, y) => x + y
Scala and Nemerle supports placeholder lambda syntax
_ + _
Scheme
(lambda (x y) (+ x y))
Smalltalk
[ :x :y | x + y ]
ML/Ocaml/F#
fun x y -> x + y
Ruby has a whole zoo of syntaxes
{|x, y| x + y }
->(x, y) { x + y }
do |x, y| x + y end
Groovy
{ x, y -> x + y }
So "(args) => body" is the most common syntax now
Scala also has this syntax that can be useful sometimes:
foo {
}
Where "foo" is a method taking a delegate as an argument. This allows to
create, what looks like, new statements. Which can be very handy for DSL's.
--
/Jacob Carlborg