fn sqr(n int) int {
return n * n
}
fn run() (fn (int) int) {
return sqr
}
fn main() {
println(run(5)) // "25"
}
I want to build success but it show an error: expected type _V_MulRet_fn (int) int, but got fn (int) int
Try
fn run() fn (int) int {
return sqr
}
Never mind, it seems not to be supported yet. Will be fixed this month.
@medvednikov And I think it will support closures like Go.
This works now with V 0.1.27 if you change the main function to
fn main() {
s := run()
println(s(5)) // "25"
}
As an improvement to this, would like to suggest
println(run()(5))
should work too. It should give
25
Currently it gives
error.v:11:14: error: unexpected `(`, expecting `,`
9 | s := run()
10 | println(s(5))
11 | println(run()(5))
| ^
Most helpful comment
Never mind, it seems not to be supported yet. Will be fixed this month.