Go is lexically scoped using blocks. In this example:
list := []string{"a", "b", "c"}
for {
list := repeat(list)
The second list
shadows the first within the for block, and doesn’t alter the outer list
variable.
Because the arguments to repeat
are evaluated before the inner list
is declared and assigned, repeat
receives the value from the outer list
solved Golang shadowing behavior explanation [duplicate]