-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
local scope in Julia 1.0 #28750
Comments
The behavior does not contradict the document. Please keep reading for more detailed explaination in the examples below (search for "this is also the default"). Dup of #28523 |
And also more explicitly
The doc is correct and the behavior (change) is intended so there's nothing to fix here (hence the close). If you think the doc could be improved in some way (the language used, the order of examples/rules) you are of course welcome to submit a PR to change that. |
Then why the code below still works inside notebook? I guess it's no longer a "global" scope?
|
#28789 (which is the link right above your question). |
But that link does not explain my question. |
And why the Repl does not? Is there a way to make it work like that by default, as Jupiter? |
It might in the future (#28789). Things have to move slower here than in packages though. I suggest further discussion goes to https://discourse.julialang.org. |
The local scope in while doesn't seem to work as documented. The following code in version 0.6.4 runs without error.
The same code running in Julia 1.0.0 gives an error indicating the the i inside the while loop is not defined.
Unless I've missed a change in the current version, I would expect the global variable
i
to be accessible inside the while loop. The same behavior also happens inside a for loop or a function.The documentation for Version 1.0 says the following:
"A new local scope is introduced by most code blocks (see above table for a complete list). A local scope inherits all the variables from a parent local scope, both for reading and writing. Additionally, the local scope inherits all globals that are assigned to in its parent global scope block (if it is surrounded by a global if or begin scope). Unlike global scopes, local scopes are not namespaces, thus variables in an inner scope cannot be retrieved from the parent scope through some sort of qualified access."
If the new behavior was intentional, then the documentation should be changed to match. My vote would be to change the behavior to match the documentation, which seems like a more sensible approach to me.
The text was updated successfully, but these errors were encountered: