New scope solution

I’m one of the users who expressed his confusions about loop scope not long ago (and got helped to understand it, many thanks).
I could give feedback for this and the other solution, from the perspective of a (not long ago) beginner to Julia.
I had trouble understanding this kind of loops:

a=1;
while true
   print(a)    # optional
   a=2 
   print(a)    # optional
   break
end

Presence or removal of one or both of the (innocent) print(a) had drastic effects on behavior of the loop, and understanding it was not at all a simple top-down following of written instructions.

The most recent solution presented this topic

also make the behavior depend on presence of a read, and to understand that, the rules are not (much) simpler than currently in v1.0 , IMHO.
But I appreciate the efforts to try to come with simpler rules.

I also believe that even for a non-beginner (or not complete beginner), it’s useful
to be able to add/remove test printing/show statements without affecting the main results, and to have simpler rules, not requiring scanning of the branches inside the loops.

So I think the previous solution by @jeff.bezanson is better in these respects, even though it is more breaking.
My understanding is that, with that solution, the while above works in global scope: assigns to the global a regardless of any printing statements, and regardless of whether a=1 is present above the loop.

As an addition, I liked the suggestions there to allow (as optional) keywords local while (same for all other currently local constructs, except functions) that would make the assignments inside the loop by default local (but without depending on presence of reads).
Inside both while and local while, one could override the behaviour with, respectively, local a=2 and global a=2, which, for ease of reasoning, should only apply to code after these statements.

I’d also very much like if the rules for scope constructs written inside functions, or other local scopes, match the above rules – perhaps in future.
This way, we’d have a single, explicit and simple set of rules everywhere.

5 Likes