You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, first of all, please accept many thanks for the great book you wrote! It's awesome to have all those gotchas collected in one place and so well explained :)
I would like to ask for a further explanation of the statement in the book that made me a bit confused though. It says that the range operator copies the slice/array/channel being iterated over (ie the range clause) on its first (and only) evaluation just before the iteration. I cannot find that in the relevant part of the Golang spec. My understanding was, on the other hand, the for-range behaves that way because it's the v (the local iterator variable) that is a copy of the slice element (not that the whole iterable thing gets copied). Please see the following snippet: https://go.dev/play/p/tEE8fW6Jxrk.
Referring to the code samples in this repo here, such a statement can be found in the book as the comment eg. to this one (or a couple of other snippets in the 4.2.x chapter):
Hello, first of all, please accept many thanks for the great book you wrote! It's awesome to have all those gotchas collected in one place and so well explained :)
I would like to ask for a further explanation of the statement in the book that made me a bit confused though. It says that the
range
operator copies the slice/array/channel being iterated over (ie therange clause
) on its first (and only) evaluation just before the iteration. I cannot find that in the relevant part of the Golang spec. My understanding was, on the other hand, the for-range behaves that way because it's thev
(the local iterator variable) that is a copy of the slice element (not that the whole iterable thing gets copied). Please see the following snippet: https://go.dev/play/p/tEE8fW6Jxrk.Referring to the code samples in this repo here, such a statement can be found in the book as the comment eg. to this one (or a couple of other snippets in the 4.2.x chapter):
100-go-mistakes/04-control-structures/31-range-loop-arg-evaluation/arrays/main.go
Lines 5 to 13 in b2152d0
The text was updated successfully, but these errors were encountered: