How to recurse a closure in Go?
Suppose I have a closure like
recur := func(){
recur()
}
Compiler says:
undefined: recur
How can i implement it? Why is it happening?
it happens because of how the order of evaluation works.
As of December 2015 (go.1.5.1), there isn't any language feature providing it.
Possible workarounds:
var recur func()
recur = func(){
recur()
}
//or
type recurF func(recurF)
recur := func(recur recurF) {
recur(recur)
}
More Info: https://github.com/golang/go/issues/226
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With