> But am hoping that the entire Go community + Go team + who ever it may
> concern
> that we all accept that we need a lambda syntax,
We do already have a lambda syntax, of course. In C#, as far as I
know, the syntax you mention is the only way to write a lambda. In Go
you can already get all the functionality of a C# lambda expression by
writing a function literal.
So I think what you are suggesting is syntactic sugar for a certain
special case of a function literal, namely one in which the types of
the parameters and results are inferred, and the body of the function
literal is a single expression that is returned.
Go is not a language that has a lot of syntactic sugar for constructs
that can be specified in another way, so there would need to be a
really compelling argument to support it--an argument somewhat more
compelling than "it would make some things a bit easier to write."
More importantly, the fact that the types must be inferred makes this
a complex construct to use in many places.
f := x => x + 1
What is the type of f? Of course we can make up a rule--but that rule
is additional complexity in the language that people have to
understand, so now we have a disadvantage countering the relatively
minor advantage (beyond the obvious disadvantage of needing to learn
an additional syntax).
I would also like a more convenient syntax for simple function
literals, but I don't see how to make it fit with Go as it stands
today.
One way to approach it might be to start from the disadvantage I
pointed out. Currently Go does type inference from right to
left--when the type of the left hand side of an assignment is omitted,
it can be inferred from the type of the right hand side. For untyped
constants Go does type determination from right to left--the type of
the left hand side of an assignment can be used to determine the type
of an untyped constant on the right hand side.
Perhaps we can invent an untyped function literal, and permit the type
of the left hand side to determine the type of the right hand side.
Then we could perhaps write something like
func map(func (int) int, []int) []int { /* body omitted */ */
map(func (x) { return x * 2 }, a)
Here the type of the function literal would be determined by the type
of the argument to map.
And the next obvious step would be to say if a function has a single
result parameter, the return statement may be implied by writing a
single expression as the last statement of the function. That would
permit
map(func (x) { x * 2 }, a)
I don't know how I feel about this. But in my opinion it would be a
more profitable approach than introducing syntactic sugar.
Ian