Sorry for another stupid question again. First of all, I am not proud of using global variables.
My question is very simple.
Three modules, A, B, and C, they are in A.jl, B.jl, C.jl.
I have defined an array called musigma in C.jl.
musigma is global, now, even if I export it, and include C.jl in all the files, the musigma is still not recognized by all the modules other than C.jl. Why?
C.jl is below:
module C
export mean_covar_init,musigma
mutable struct Mean_covar
w::Float64
end
const musigma = Array{Mean_covar,1}() # const is global
function mean_covar_init()
resize!(musigma, 2)
for k in 1:2
musigma[k] = Mean_covar(0.0)
musigma[k].w = 2.0
end
println(musigma)
return nothing
end
end
The function mean_covar_init() just initilize musigma and print it.
B.jl is below
module B
include("C.jl")
using .C
export init
function init()
println(musigma)
end
end
the function init() just print the musigma from module C.
A.jl is below, it is the main program and it just display the musigma from module B and C,
include("B.jl")
using .B
include("C.jl")
using .C
mean_covar_init()
init()
In Julia, I just run
include("A.jl")
because I know this is a way to run xxx.jl program, and what is show in REPL is
julia> include("A.jl")
Main.C.Mean_covar[Main.C.Mean_covar(2.0), Main.C.Mean_covar(2.0)]
Main.B.C.Mean_covar[]
However, what I expected should be
julia> include("A.jl")
Main.C.Mean_covar[Main.C.Mean_covar(2.0), Main.C.Mean_covar(2.0)]
Main.C.Mean_covar[Main.C.Mean_covar(2.0), Main.C.Mean_covar(2.0)]
I mean, in A.jl,I do
mean_covar_init()
first, so musigma has been initialzied. Since its const and global, its value should have been stored.
Next, in A.jl I did
init()
This function display the musigma from module B.
I expect that this musigma should be the same as the musigma in C. Because they should be the same.
Now, why in Module B, musigma is not recognized as has been initialized?
Could anyone please give some hints, what am I missing?
Thank you very much indeed in advance!