My mental model is that x[:] += 1
is turned into x[:] = x[:] + 1 which is equivalent to x[:] = x + 1 which then is turned into a setindex! call. See http://docs.julialang.org/en/release-0.3/manual/arrays/#assignment I don't know if the last step is accessible to the user (for metaprogramming), would be interesting to learn about that. Best, Tamas On Sat, Mar 14 2015, 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