我的文件中有一个模块全球.jl它定义了一个名为“data”的全局多维数组:
module Global
export data
# GLOBAL DATA ARRAY
data = zeros(Int32, 20, 12, 31, 24, 60, 5);
end
我有一个main.jl它使用这个全局变量:
include("global.jl")
using .Global
println(data[14,1,15,18,0,1])
我收到以下错误:
$ time /usr/local/julia-1.2.0/bin/julia main.jl
ERROR: LoadError: BoundsError: attempt to access 20Ã12Ã31Ã24Ã60Ã5 Array{Int32,6} at index [14, 1, 15, 18, 0, 1]
Stacktrace:
[1] getindex(::Array{Int32,6}, ::Int64, ::Int64, ::Int64, ::Int64, ::Vararg{Int64,N} where N) at ./array.jl:729
[2] top-level scope at /usr/home/user/test1/main.jl:4
[3] include at ./boot.jl:328 [inlined]
[4] include_relative(::Module, ::String) at ./loading.jl:1094
[5] include(::Module, ::String) at ./Base.jl:31
[6] exec_options(::Base.JLOptions) at ./client.jl:295
[7] _start() at ./client.jl:464
in expression starting at /usr/home/user/test1/main.jl:4
我想我缺少如何在 Julia 的单独文件中共享全局变量。欢迎任何帮助。