我无法从 REPL 运行我的程序。 当我尝试这个时:
julia> ARGS = ["hello", "world"] include("test.jl")
error: ERROR: syntax: extra token "include" after end of expression
你怎么能让它变成 2 行: 如果我尝试先运行:
ARGS = ["hello", "world"]
Error: ERROR: cannot assign variable Base.ARGS from module main
但是命令行工作没有任何问题
我试过了:
julia> include("test.jl", ARGS = ["hello", "world"])
julia> include("test.jl","hello", "world")
他们都没有工作。
ARGS,当 Julia 在 REPL 运行时加载的 Main 的字符串命令行参数数组是只读的。因此,您无法重新分配它。
但是,您可以在 REPL 上创建一个新模块,并通过模块命名空间中的 include 来运行程序,因为 Main.ARGS 与另一个模块的 ARGS 不同。
假设 test.jl 包含单行
println(prod(ARGS))
因此,您可以在 REPL 命令行中键入以下内容(包括使用 Enter 键(:
julia> module test
ARGS=["hello", "world"]
include("test.jl")
end
然后,输出应为:
helloworld
Main.test