Re: [go-nuts] initialization loop ?

2021-10-25 Thread Ian Lance Taylor
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.

Re: [go-nuts] initialization loop ?

2021-10-23 Thread Michael Ellis
> 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

Re: [go-nuts] initialization loop ?

2021-10-22 Thread Ian Lance Taylor
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

Re: [go-nuts] initialization loop ?

2021-10-22 Thread Elemer Pixard
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

Re: [go-nuts] initialization loop ?

2021-10-22 Thread Jan Mercl
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 =

[go-nuts] initialization loop ?

2021-10-22 Thread dana...@gmail.com
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