#Why does this program panic on run time?

6 messages · Page 1 of 1 (latest)

latent harbor
reef flicker
#

from the spec:

The assignment proceeds in two phases. First, the operands of index expressions and pointer indirections (including implicit pointer indirections in selectors) on the left and the expressions on the right are all evaluated in the usual order. Second, the assignments are carried out in left-to-right order.

#

i.e. a and a[0] are both evaluated before either of the assignments happen

frosty meteor
#

Is this also why a, b = b, a works?

dusty plover
#

Actually you could argue not