I recently went through Golang's "Language Specification" https://golang.org/ref/spec#Order_of_evaluation but found the order of evaluation being different from what it is explained in this document.
For example, it says:
a := 1
f := func() int { a++; return a }
x := []int{a, f()} // x may be [1, 2] or [2, 2]: evaluation order between a and f() is not specified
Then I tried with this code:
package main
import "fmt"
func main() {
for {
result := evaluate()
if result == 1 {
break
}
}
}
func evaluate() int {
a := 1
f := func() int { a++; return a }
x := []int{a, f()}
fmt.Println(x)
return x[0]
}
I found the value of slice x is always [2,2]. Is there anything I misunderstand?
Thanks in advance.