`x[:]` works, because the values of `x` can be changed. Nevertheless, `x` itself (its address) cannot be changed. When you do `x=x+1` in the callee, it will bind `x` to a new local variable, which has different address from the previous `x`.
The same lethargy applies to `x[1] += 1`. On Saturday, March 14, 2015 at 1:33:56 PM UTC+1, John wrote: > > I was surprised today that the following function doesn't modify an input > array > function f(x) > x += 1 > end > However, now I understand that x += 1 is just syntactic sugar for x = x + > 1. > The reasoning from https://github.com/JuliaLang/julia/issues/7052 makes > sense. > OTOH, x[:] += 1 does modify the input array. > But that contradicts my mental model of how the language works, because > x[:] == x. > Is there some special magic going on during parsing? > > related: > https://groups.google.com/forum/#!searchin/julia-users/inplace/julia-users/fHB7WLiiLsQ/U6dJBqcNLg4J > >
