Skip to content
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

BUG in a42a? #28

Closed
sglyon opened this issue Jul 2, 2015 · 4 comments
Closed

BUG in a42a? #28

sglyon opened this issue Jul 2, 2015 · 4 comments

Comments

@sglyon
Copy link
Member

sglyon commented Jul 2, 2015

Here is a (partial) traceback:

ERROR: UndefVarError: e not defined
 in a42a at /Users/sglyon/.julia/v0.4/Roots/src/fzero.jl:165
 in fzero at /Users/sglyon/.julia/v0.4/Roots/src/Roots.jl:114

I've looked over and over this function and cannot figure out why this is happening. The && should short-circuit so the distinct(f, a, b, d, e) should only run after the first iteration has completed. Then e is defined towards the end of every iteration, so by the time this ever executes e should be in scope...

EDIT: link to the line in question

@yuyichao
Copy link

yuyichao commented Jul 2, 2015

I think the scope of the variable does not escape the iteration unless you specify so.

julia> function k1()
           for i in 1:3
               i == 1 || println(f)
               f = 1
           end
       end
k1 (generic function with 1 method)

julia> function k2()
           local f
           for i in 1:3
               i == 1 || println(f)
               f = 1
           end
       end
k2 (generic function with 1 method)

julia> k1()
ERROR: UndefVarError: f not defined
 in k1 at ./none:3

julia> k2()
1
1

@sglyon
Copy link
Member Author

sglyon commented Jul 2, 2015

Hmm that's subtle. I didn't know that.

@yuyichao
Copy link

yuyichao commented Jul 2, 2015

Yeah. The document of the scope definitely needs more comprehensive documentation JuliaLang/julia#9955

@jverzani
Copy link
Member

jverzani commented Jul 2, 2015

Hopefully this f5f3789 fixes the issue. (I couldn't reproduce the error to be sure.)

@jverzani jverzani closed this as completed Jul 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants