How to access global variables within a module?


#1

hello, maybe a stupid one, but I failed to find relevant documents…

I have something defined in REPL (with const), but they’re not accessible within the functions defined within a module. What should I do?

thanks.


#2
julia> const a = 1
1

julia> module A
           using ..Main: a
           println(a)
       end
1
Main.A

#3

Pass the variables as arguments to the functions.


#4

wow… where is any documentation about ..Main ???


#5

https://docs.julialang.org/en/v1/manual/modules/index.html#Standard-modules-1

https://docs.julialang.org/en/v0.6.0/manual/modules/#Relative-and-absolute-module-paths-1


#6

oh, it’s about “relative module path”.

so, in your first example, why need .. before Main ?

I mean, when we use using inside a module, normally we don’t need that .., and it would automatically search “outside”, right?


#7

You don’t need the .. before Main. I just tried it.


#8

thx