FAQ
The colon-equals operator by definition creates a new variable, so it is a little opposite that you're suggesting it should modify the thing being iterated over. It could make sense with regular equals if range were actually designed that way, but due to the go1 compatibility promise this is not possible.

(PS: if the second value in the range clause could be assigned to and have the thing you are iterating over actually change it would effectively be a "by reference" value, something Go doesn't have. In addition this would be very complicated if you wanted to extend it to maps since setting a value for any given key could possibly cause the map to rearrange its internal structure (this is the reason map values are not addressable). The map set code would have to be able to alter the by-reference variable to its new position in the map's value list for it to be possible, and that doesn't sound like a simple thing to do in general).

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 19 of 26 | next ›
Discussion Overview
groupgolang-dev @
categoriesgo
postedOct 25, '14 at 9:46a
activeOct 29, '14 at 3:01p
posts26
users13
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase