On Sat, Oct 23, 2021 at 9:05 AM Michael Ellis wrote:
>
> > The rules for when an initialization loop occurs are part of the language
> > spec: https://golang.org/ref/spec#Package_initialization.
>
> Thanks for the link. It helps with questions I've had recently about package
> initialization.
> The rules for when an initialization loop occurs are part of the language
spec: https://golang.org/ref/spec#Package_initialization.
Thanks for the link. It helps with questions I've had recently about
package initialization. Can you confirm that the statement
"If a package has imports, the
On Fri, Oct 22, 2021 at 11:38 AM Elemer Pixard wrote:
>
> This should be possible, because the slice simply contains the address of the
> function.
> Why the compiler cares what the function will be doing when called ?
> Equivalent code will work in several other languages.
The rules for when
This should be possible, because the slice simply contains the address of
the function.
Why the compiler cares what the function will be doing when called ?
Equivalent code will work in several other languages.
On Friday, October 22, 2021 at 2:59:36 PM UTC-3 Jan Mercl wrote:
> testSlice
testSlice mentions printLen, printLen mentions testSlice. The specification
explicitly forbids such init cycles.
On Fri, 22 Oct 2021, 19:51 dana...@gmail.com, wrote:
> Why do I get an initialization loop in the following program?
>
> ```go
> package main
> import "fmt"
> var testSlice =
Why do I get an initialization loop in the following program?
```go
package main
import "fmt"
var testSlice = []func(){printLen}
func printLen() {
fmt.Print(len(testSlice))
}
func main() {
printLen()
}
```
Playground Link: https://play.golang.org/p/tJenMMaWex6
Using go1.17.2
--
You