I recently ran into a bug in my code related to some unintuitive (to me) behavior of array indexing.
Given an array, say
A = reshape(collect(1:16),(4,4))
we can access elements of the array through multiple indexing calls
A[1:2,3:4][1:2] # [9, 10]
However, what I was unaware of was that it is not possible to set values through sequential applications of array indexing, i.e.
A[1:2,3:4][1:2] = [1;1]; A[1:2,3:4][1:2] # [9,10]
However, I figured out that I can get this to work through the use of views
B = view(A,1:2,3:4); B[1:2] = [1;1]; A[1:2,3:4][1:2] # [1,1]
Could someone please explain why I shouldn’t expect the first way to work, i.e. why sequential applications of indexing does not allow for setting array value?