This means that allowing to mutate a globally defined object is more dangerous than just creating a new one. Which even more supports my point that if you allow v[1]=1 inside loops, then you should allow v = [1 1] as well.
Having different definitions than everyone else means that there will be trouble when you communicate with other people.
True. But it seems like different people have different notions of “object”, depending on their background.
Do you have a reference to the definition of “object” in Julia documentation?
I could not find one, so I use an everyday notion.
I had the assumption here that you wanted to understand and learn how Julia scope behaved but this is more and more getting into just repeating Another possible solution to the global scope debacle so I’ll just refer to that.
Because === computes “programmatic indistinguishability” which is the one true notion of object equality. Everything else is somewhat arbitrary and happens to be convenient sometimes and wrong other times.
I meant “same” with respect to intrinsic properties (values) that changed at mutating, not identity (which is preserved, just like I’m still Vic even though this discussion has made me smarter ).
I should yet find time to read the paper you suggest.
For now, I’d say that programmatic indistinguishability (and ===) is good for judging identity, but not equality (compares values) of mutable objects.
Plus, an object preserves it’s identity, but if mutated it changes in value, so I can’t say it remains equal to itself across time.
I came across this thread while encountering a similar but slightly different issue.
I have to say this behavior is extremely confusing. The confusion being that the 1st loop example succeeds with no issues, but the 4th loop example fails. This seems inconsistent. If the variable is out of scope both of those loops should fail. However the 1st one succeeds, meaning that the code had no issue locating the variable a and reading the value, despite it supposedly being out of scope. The scoping of the variable a should not change depending on the content of the loop (other than an invocation of global). It is changing the meaning of print(a) based on there being a later write to a inside that scope. If print(a) can find the variable then a = a+1 should too.
If this succeeds: while true; print(a); break; end
Then this should also: while true; print(a); a = a + 1; break; end
Based on how many questions I’ve found regarding this behavior online, I think this decision should be re-evaluated. In my case I had a function where I changed a parameter name, so that local references to that parameter should have immediately broken the next time I called it because that variable does not exist in that local scope, however that wasn’t the case, it just silently kept “working” (silently failing) because there happened to be a global with the same name. I’m fine with the decision to have the local scope not recognize global scope variables automatically, however in the 1st case it is, and in the 4th case it is not. I think the behavior should be one way or the other.