> > The problem was that I repeatedly mentally misread 'indexing' for 'index > evaluation'. As the index is a constant in this case, it lead me to believe > it cannot have any effect on the result. But it's the 'indexing', the > actual time when the value is loaded using the index, which is exempt from > the 'left-to-right' evaluation rule for operands. >
I actually read the following part of the spec <https://golang.org/ref/spec#Order_of_evaluation>: *Otherwise, 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.* and inferred "when evaluating the operands of an expression, assignment, or return statement" every expression that is not a "function call, method call or communication operation" has an undefined order of evaluation, including (as the later paragraph clarifies) index expressions. Consider for example: https://play.golang.org/p/xGaEDjTuzw To my understanding, it is undefined when "j-1" evaluates, hence that code _might_ panic. But maybe I read/inferred that incorrectly? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.