Hi!
It was not clear to, after Reading the section Scope of variables in the docs, that a variable is defined for a whole block, no matter where the variable is defined within the block. Perhaps it would be worthwhile calrifying this in the docs since understanding the scoping rules fully is very important. Perhaps adding something like this:
============================================================
Note that the location of a variable definition within a scope block is irrelevant (similar as with the
local and global keywords as the following two examples show:
for i = 1:10
foo = 1
for j = 1:10
foo = 10
end
bar = foo + 1
end
for i = 1:10
for j = 1:10
foo = 10
end
bar = foo + 1
foo = 1
end
whereas the following example will fail:
for i = 1:10
for j = 1:10
foo = 10
end
bar = foo + 1 # Here foo is not defined
end
============================================================
I hope it is okay to ask for documentation improvements through issues, since creating a pull request for beginners needing good documentation is not so easy.
All the best
Jan
Your last exemple is similar to the previous one, and works, no?
My 3rd example doesn麓t work, whereas my 1st and 2nd example does.
It works on 0.6 rc1 and master (but not 0.5)
This looks like a regression to me:
julia> for i = 1:10
for j = 1:10
foo = 10
end
bar = foo + 1
end
julia> foo
10
julia> bar
ERROR: UndefVarError: bar not defined
I don't see how it could make sense for this to assign foo as a global but not bar. Even worse:
julia> function f()
for i = 1:1
x = 0
end
x
end
f (generic function with 1 method)
julia> f()
0
This was an error in versions <= 0.5.x.
Bisected to 046abcdf2e0bc64e10706ea30fa4983e928fc25c. cc @vtjnash
Can we assign the regression part of this to someone so we know who's working on it?
@JeffBezanson @vtjnash anyone else capable of fixing this?
Most helpful comment
Can we assign the regression part of this to someone so we know who's working on it?