Function not defined when occurring in else-clause inside of another function

See JuliaLang/julia#15602. You need to use anonymous functions:

function test(flag=true)
    if flag
        myfunc = () -> 1
    else
        myfunc = () -> 0
    end
    println(myfunc())
    return
end
2 Likes