So you mean getindex and setindex! should behave the same? I can take a few guesses why you might think that way (if they are wrong, please ignore…):
- If you are from python (or other language that returns view from indexing by default) then the short answer is that it’s been considered but it’s breaking enough and the performance of operations on views are bad enough that we believe it’s better to be explicit when views are required. (The performance issue isn’t a problem for python since it was slow anyway).
- If you are from C++ (or other languages that uses getindex to implement setindex!) then julia has a completely different object model and you’ll get a lot more related surprises.
Well, you were never comparing the two. For the original code, the
getindex, i.e. the first bracket, is definitely what gives you the behavior you didn’t expect. Now, if you were comparing it to something that you never mentioned, then sure, adding the second one could be how you get from a working version to this version. There are just so many changes that you could’ve made though, so it’s impossible for others to guess what was the last change you made. FWIW, removing the first square bracket will also make it “work”.