Strange Variable Behavior



I am new to Julia. I am using Atom and the uber-juno package (and its associated packages).

I have discovered some strange behavior. I have a variable to which I’ve saved a time step, dt=5E-3. In the workspace it shows the value correctly as 5E-3 but when I go to the REPL and call it, every once in awhile it will return 1E-3! There doesn’t seem to be a pattern. It just sometimes returns the wrong value for something I thought was saved there.

What could be causing this?


Can you share an example?


Sure, here is the code snippet. So when I call the variable dt from REPL it sometimes returns 1E-3 instead of 5E-3. Any idea why? Any place I could look to further investigate why? Maybe something in the workspace?

## Input
## =======================================
n = 17; # grid size
U = 1; # velocity [m/s]
H = 1; # square grid height [m]
h = H / ( n - 1 ); # grid spacing [m]
x = linspace(0,H,n)
y = linspace(0,H,n)
dt = 5E-3 # time step [s]


Some other code of yours is modifying dt. Search through the code you’ve run and look for dt.


(This is another reason to get out of the habit of writing long scripts that do all computations with local variables. Write functions and pass data with parameters, not globals! Besides being a good programming habit, this is also crucial for performance in Julia.)


Thanks for the replies!

I’ll review my code again but I was getting this behavior in the REPL. I had already run my script and it was done executing. That is why I found it strange and didn’t understand how it could be changing after I had already set it in the script.

Also - thanks for the tip on programming. Let me make sure I understand. You are saying chop up the script and have functions (that i define) do the computations? Call them from a central (shorter) script?