behaviours of get/setindex on the left hand side.
I think it’s a little confusing to call the first square brackets at fault because it would work without the second set, eg, b2[b2] .= false should be fine, but i guess that is a technical answer - how julia uses getindex and setindex in this case
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”.
I did look at learning python a while back, but they used the phrase “syntactic sugar” too many times in the first video lecture
Technically i’d be a former octave user, though i only used it a little, enough to pass a few MOOCs
Naively i would’ve thought all indexing on the left would be or reduce to setindexes
tbh I’m not sure if that’s fair use of the ‘moving the goalposts’ concept but point taken - I say this because it seems very much stating the obvious that it works with just the one set of brackets
Is there any chance that we could have this behaviour changed at some point, specifically for the left-hand side? The work around isn’t too bad but I at least would find the double-indexing set method quite convenient at times
Maybe a diy job I guess, it shouldn’t be too hard to add a method to setindex! make a function to combine indexes
That is extremely unlikely (so unlikely that I don’t think it is worth spending too much time on it).
Also, a good default approach when you learn a language is to give the existing implementation a bit more of the benefit of the doubt and just blindly accept that things are the way they are for some reason. After a while, when you are more familiar with things, you might see that the behavior actually made sense. If it still feels odd, and then voicing concerns might be reasonable.