0
votes

EDIT: In the end it had nothing to do with it. I'm answering for anyone in a similar situation.


I discovered Julia a month ago and have been fascinated with it since then. However, it seems compilation (or a variable scope) is still not clear for me.

I have this module in plots.jl:

module plottinghhkp

instance_path = "somestring"

function dosomething()
  ...
end

...
end

and then include it in the REPL to run module functions

julia> include("plots.jl")
...
julia> hhkplot.instance_path
julia> "somestring"

I then modify instance_path, and re-import using include again, but instance_path shows old value instead of the new value:

julia> include("plots.jl")
...
julia> plottinghhkp.instance_path
"somestring"

My solution was to rename the variable to instancepath so that a new symbol is created, however, autocomplete now shows:

julia> plottinghhkp.
instance_path  instancepath
julia> plottinghhkp.instancepath
"newvalue"
julia> plottinghhkp.instance_path
"somestring"

when the instance_path symbol does not exist anymore in the module. Creating a fresh environment with workspace() never ends.

Why is this happening? Do I need to explicitly load Julia with no precompiling, or add __precompile__(false) to the module? Or is it something about the variable scopes?

Thanks.

1

1 Answers

0
votes

I managed to solved the problem. Of course, it had nothing to do about compilation. It was a namespace problem. There were two variables under the same name, but each had a different namespace since one of them was wrapped around a module.

If you come across a similar situation, be sure to look at all your modules/namespaces. Working with different namespaces would be ideal so you don't have any clashes.