-
-
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
Nested function introduces a variable scoping bug #11065
Comments
Arguably the second behavior is the correct one, and the first one is the bug. Variables only used within a loop are supposed to be newly allocated on each iteration. |
This remark is inaccurate. I rewrite the above examples with i = 1
while i <= 2
if i == 1
z = "z is defined"
println("Iteration $i: $z")
elseif i == 2
try
println("Iteration $i: $z")
catch
println("Iteration $i: z is undefined")
end
end
i += 1
end Iteration 1: z is defined i = 1
while i <= 2
g() = z
if i == 1
z = "z is defined"
println("Iteration $i: $z")
elseif i == 2
try
println("Iteration $i: $z")
catch
println("Iteration $i: z is undefined")
end
end
i += 1
end Iteration 1: z is defined Now in the second example, |
Turns out this issue was described in this comment: #1571 (comment) |
Also, I should have said "for loop" instead of "loop". |
Are there performance implications to having |
This is a bug related to the discussion in [https://groups.google.com/forum/?fromgroups=#!topic/julia-users/ddsrBhXFJsc]:
I modified the code and tested it (v0.3.6):
Normal code:
Iteration 1: z is defined
Iteration 2: z is defined
Now I define a function
g()
inside and get a bug:Iteration 1: z is defined
Iteration 2: z is undefined
[pao: syntax highlighting]
The text was updated successfully, but these errors were encountered: