-
-
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
Problems with local scope #11696
Comments
This is the documented correct behavior. See http://julia.readthedocs.org/en/release-0.3/manual/variables-and-scoping/ In particular, the following text and the examples below it.
|
Actually when I read the document on the variable scope just now, it isn't very clear on what's the difference between a @krychu also note that you didn't call the function in your second example (although it doesn't make a difference) |
Sorry I forgot to add The docs say:
which would suggest Then the docs say:
and this:
which would suggest that |
Also this part is confusing
which doesn't seem to be true as this script (run from outside the interactive prompt): y = 0
for i = 1:1; y = 10; end
println( y ) modifies the global I'm pointing these out so that the docs can be made clearer for newcomers (like me). |
This is soft vs hard scope of functions which is not described in the docs, its issue is #9955. And also have a look at #10559. And if anyone improves the scope docs, the meaning of global should be defined: i.e. that a global is a module-wide global. There are no truly global globals (which is different from Matlab). |
Thanks! |
Closing as dup of #9955. |
Hello,
Consider two examples:
According to the docs both the
for
loop and thefunction
definition should introduce a new scope with an inner variablex
. But this doesn't seem to be the case for thefor
loop. I'm sure I'm missing something (?)Here's the relevant snippet from the docs:
"As a consequence, the only way to assign to a global variable inside a non-top-level scope is to explicitly declare the variable as global within some scope, since otherwise the assignment would introduce a new local rather than assigning to the global."
Mac OS, Julia 0.3.9
The text was updated successfully, but these errors were encountered: