I ran into some weird behavior that I don’t understand. When having two possible function declarations inside an if-else-statement which is wrapped in some outer function, the assignment inside the else-clause doesn’t work. ("Yah, I know that’s bad programming style and I changed my code. However, I would really like to understand what’s going wrong here )
Here is a minimum working example:
function test(flag=true) if flag myfunc() = 1 else myfunc() = 0 end println(myfunc()) return end
Running this function as
test(flag=true) works perfectly fine and prints me a
1. However, when calling it as
test(flag=false) the code crashes with
ERROR: UndefVarError: myfunc not defined.
Why is this happening?
Thank you very much