When evaluating the operands of an expression, assignment, or return statement, all function calls, method calls, and communication operations are evaluated in lexical left-to-right order.
For example, in the assignment
y[f()], ok = g(h(), i()+x[j()], <-c), k()
the function calls and communication happen in the order f()
, h()
, i()
, j()
, <-c
, g()
, and k()
. However, the order of those events compared to the evaluation and indexing
of x
and the evaluation of y
is not
specified.
a := 1
f := func() int { a = 2; return 3 }
x := []int{a, f()} // x may be [1, 3] or [2, 3]: evaluation order between a and f() is not specified
Floating-point operations within a single expression are evaluated according to the associativity of the operators. Explicit parentheses affect the evaluation by overriding the default associativity. In the expression x + (y + z)
the addition y
+ z
is performed before adding x
.
--
The term `undefined behavior` or even `undefined` appears nowhere in
the Go spec (either 1.0 or tip), which I interpret to be a good thing.
If multiple cases can proceed, a uniform pseudo-random choice is made to decide which single communication will execute.
I thought that was the idea. If people can predict the behavior, they
will write code that assumes it. Maps deliberately randomise iteration
order to enforce this concept.
Do calls function f on each element of the ring, in forward order. The behavior of Do is undefined if f changes *r.