This question already has an answer here:
- Golang mixed assignation and declaration 3 answers
In this snippet
list := []string{"a", "b", "c"}
for {
list := repeat(list)
...
func repeat(list []string) []string {
...
it is clear that list
variable used as the argument to repeat()
function is the outer, shadowed list variable. Now my question is, how would a Go language lawyer explain this behaviour? At first glance, I thought the declaration of the inner list variable would have preceded the repeat(list)
expression evaluation.
</div>