-
-
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
global keyword in inner scopes #7264
Comments
This appears to be a symptom of the REPL having to use a "fake" global scope for code typed into it. Both examples work fine from files. The manual obliquely refers to the fact that in the REPL |
@elextr All the manual says is that global scope in the REPL is inherited with local variable semantics into inner scopes. So, you can assign to a global from an inner scope without having to use the Edit: Sorry, this comment is a little confusing. What I should have said is that it is inherited "like" a local variable, but is still global and should be accessible via the |
The part of the manual I was referring to is in http://docs.julialang.org/en/release-0.2/manual/variables-and-scoping/ "Due to the special identification of the prompt’s scope block with the global scope, it is not necessary to declare global y inside the loop. However, in code not entered into the interactive prompt this declaration would be necessary in order to modify a global variable." This implies that at the REPL the "global" is not the true global scope. Indeed having the REPL use the true global scope would be dangerous, a user typing at the REPL could make a (un)lucky choice of name and affect the REPL or Julia itself. But it seems that Julia doesn't hide the differing semantics well enough. |
So, the
|
In the REPL, In 0.3 a lot of the REPL has been changed, but I don't know if this has been fixed. |
No, in the REPL global variables are the same as any other global variables. If I type |
@JeffBezanson So, this issue is a bug. |
global
does not always refer to the global scope.Another example:
Version information:
Note: I believe this same behavior occurs on the latest snapshot.
The text was updated successfully, but these errors were encountered: