Variables not recalculating while reloading modules

What happens if you explicitly say using Mymodule after changing/saving/re-including it?

Tested it myself with Revise. I see the same behavior as you. I would file an issue on Revise.jl.

Actually, this seems like a natural consequence of how Revise works. It doesn’t scan the entire module for inter-variable dependencies (it would have to do this as strings anway, since julia doesn’t store this information in any form; i.e. y = 10, not 10*x as far as julia is concerned) and it doesn’t reinclude all of the source from scratch, as that’s exactly what it’s trying to avoid. Variable capture in functions happens to be by binding, so if you made y() = 10*x you should indeed see it change along with x, but otherwise it is independent. A change like y = 11*x would redefine y.

I think the takeaway here is to design your global variable interface differently :sweat_smile:. Maybe as mutable structs, Dicts, etc… Also beware that global variables in julia are bad for performance unless they are const. Check out the performance tips of the manual for more info.

1 Like