-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scope query in assignment / misunderstanding ? #6522
Comments
Quoting from http://docs.julialang.org/en/release-0.2/manual/variables-and-scoping/ :
The assignment |
thank you and I see that's the case even when I remove the let loop.
|
You are hitting the gap between global and local variables. This irregularity between global and local variables has been discussed before. I think that Julia has also been patched up so that code outside of functions often seems to work similar to code inside functions, but this case seems hard to patch up. I for one would welcome a more regular treatment, but I'm not sure what would be a reasonable way forward. My best advice would probably be to write as little code in global scope as possible - it usually works as you expect, but not always. |
Thank you. That's very helpful. I'll follow your advice - for shorter scripts I can just wrap them in let blocks and have a liberal sprinkling of locals |
I've read #423 and #424 and the manual and I'm still not clear why the following happens and whether it's meant to. I'm hoping I've not done something stupid.
I put the following in a file and ran it with Julia 0.21 on windows
The last println prints
header without loop is => set in inner loop
why isn't it
header without loop is =>initialised
i.e. shouldn't the trade_header assignment in the for loop have created a new local variable?
I'm guessing that the trade_array should be considered as an assignment as I'm only changing the contents, not the array pointed to.
The text was updated successfully, but these errors were encountered: