You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi everyone, sorry to bother. I encountered a weird behaviour recently, and I wanted to show it.
I define a function in an if statement; it is defined in one way if "flag" is true and in another otherwise. But when I run and the code goes through the first case, the second definition is used even if that code is not passed through at all.
Example: the output of this code
function test_bug_1(flag)
c=987;
if flag
d(x)=x
else
d(x)=x-c
end
println(d(1))
end
test_bug_1(true)
The output is -986 instead of 1. If I "correct" the code in the following way it works as intended:
function test_bug_2(flag)
c=987;
if flag
d1(x)=x
d=d1
else
d2(x)=x-c
d=d2
end
println(d(1))
end
test_bug_2(true)
Output: 1
Here are the info from versioninfo():
julia> versioninfo()
Julia Version 1.2.0
Commit c6da87f (2019-08-20 00:03 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, broadwell)
Is this something I should have predicted in some way? Or is something weird happening? I greatly appreciate all the help.
The text was updated successfully, but these errors were encountered:
Hi everyone, sorry to bother. I encountered a weird behaviour recently, and I wanted to show it.
I define a function in an if statement; it is defined in one way if "flag" is true and in another otherwise. But when I run and the code goes through the first case, the second definition is used even if that code is not passed through at all.
Example: the output of this code
The output is -986 instead of 1. If I "correct" the code in the following way it works as intended:
Output: 1
Here are the info from versioninfo():
julia> versioninfo()
Julia Version 1.2.0
Commit c6da87f (2019-08-20 00:03 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, broadwell)
Is this something I should have predicted in some way? Or is something weird happening? I greatly appreciate all the help.
The text was updated successfully, but these errors were encountered: