-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
arrow functions or lambda functions support #321
Comments
Thank you for your proposal. We will consider it seriously. |
Define lambda functionsf := (arg1 ArgType1, arg2 ArgType2, ..., argN ArgTypeN) => expr(arg1, arg2, ..., argN)
g := (arg1 ArgType1, arg2 ArgType2, ..., argN ArgTypeN) => {
...
return expr(arg1, arg2, ..., argN)
} Note: output parameters are always omitted. Passing lambda functions as function parametersfoo.Bar(arg => expr(arg))
foo.Bar((arg1, arg2, ..., argN) => expr(arg1, arg2, ..., argN))
foo.Bar((arg1, arg2, ..., argN) => {
...
return expr(arg1, arg2, ..., argN)
}) Types of input parameters can be omitted if they can be automatically deduced. For example, in Go we can write code as following: foo.Map(func(x float64) float64 { return x*x }) And in Go+ it can be: foo.Map(x => x*x) |
If we write the code below: m := 100
cc := (arg1, arg2, arg3) => {
m := 10
dd := (d1, d2, d3) => {
println(m);
}
} what is the print? or compile error? |
I'd like ES6 style |
Will compile fail because types of input parameters are not specified. If we do this, its output is "10\n". |
To make the following code foo.Map(x => x*x) equals to f := x => x*x
foo.Map(f) We automatically deduce the prototype of lambda So, Defining lambda functions will be same as passing them as function parameters. f1 := arg => expr(arg)
f2 := arg => {
...
return expr(arg)
}
g1 := (arg1, arg2, ..., argN) => expr(arg1, arg2, ..., argN)
g2 := (arg1, arg2, ..., argN) => {
...
return expr(arg1, arg2, ..., argN)
} |
How to write a lambda without parameters and multiple return values? f1 := => expr1, expr2 or f1 := () => (expr1, expr2) |
Will be: f1 := => (expr1, expr2) // or:
f1 := () => (expr1, expr2) |
like es arrow function
(x,y) => x+y
or like python lambda functiong = lambda x:x+1
The text was updated successfully, but these errors were encountered: