我无法从 REPL 运行我的程序。 当我尝试这个时:
julia> ARGS = ["hello", "world"] include("test.jl")
error: ERROR: syntax: extra token "include" after end of expression
如何将其变成两行: 如果我尝试先运行:
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 中创建一个新模块,并通过包含在该模块的命名空间中来运行您的程序,因为 Main.ARGS 与另一个模块的 ARGS 不同。
假设 test.jl 包含单行
println(prod(ARGS))
然后您可以在 REPL 命令行中键入以下内容(包括使用 Enter 键):
julia> module test
ARGS=["hello", "world"]
include("test.jl")
end
输出应该是:
helloworld
Main.test
关于julia - 有没有办法在 REPL 模式下传递参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52911684/