Re: [go-nuts] Re: Q about defer

2021-12-24 Thread Kevin Malachowski
Actually, this part is a bit more relevant: "That is, if the surrounding function returns through an explicit return statement, deferred functions are executed after any result parameters are set by that return statement but before the function returns to its caller." On Fri, Dec 24, 2021, 12:50

[go-nuts] Re: Q about defer

2021-12-24 Thread Kevin Chowski
Specifically, this part from the #Defer_statements linked by Peter: "For instance, if the deferred function is a function literal and the surrounding function has named result parameters that are in scope within the literal, the deferred function may access and modify the result parameters befo

Re: [go-nuts] Re: about for range with array?

2021-12-24 Thread Ian Lance Taylor
On Fri, Dec 24, 2021 at 9:38 AM Kevin Chowski wrote: > > On Friday, December 24, 2021 at 10:08:23 AM UTC-7 cuiw...@gmail.com wrote: >> >> does the range expr will be evaluated means when range expr is slice, the >> slice header will be copy, and when range expr is array, array will be coy? > > >

[go-nuts] Re: about for range with array?

2021-12-24 Thread Kevin Chowski
Comments inline below: On Friday, December 24, 2021 at 10:08:23 AM UTC-7 cuiw...@gmail.com wrote: > in the lang spec , it says: > *The range expression x is evaluated once before beginning the loop, with > one exception: if at most one iteration variable i

[go-nuts] about for range with array?

2021-12-24 Thread xie cui
in the lang spec , it says: *The range expression x is evaluated once before beginning the loop, with one exception: if at most one iteration variable is present and len(x) is constant, the range expression is not evaluated.* https://go.dev/play/p/frLAvStO

[go-nuts] Re: Q about defer

2021-12-24 Thread peterGo
The Go Programming Language Specification https://go.dev/ref/spec Defer statements https://go.dev/ref/spec#Defer_statements Peter On Friday, December 24, 2021 at 8:34:58 AM UTC-5 muhorto...@gmail.com wrote: > https://play.golang.com/p/lypWMc6Kuff > Why do we get 2 in test() and 1 in another

[go-nuts] Q about defer

2021-12-24 Thread Денис Мухортов
https://play.golang.com/p/lypWMc6Kuff Why do we get 2 in test() and 1 in anotherTest()? Is it related to the definition of the variable in the output? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop recei