【发布时间】:2018-04-24 13:36:20
【问题描述】:
我承认对 Julia 不熟悉。但是,通过查看各种文档,我找不到我(可能非常简单)问题的适当答案。
我从 Matlab 中了解到的
考虑文件夹src/ 中的两个文件,分别称为main.m 和anotherfunc.m
function main
anotherfunc(0)
end
和
function anotherfunc(x)
disp(sin(x))
end
我会在命令窗口中运行 main 并查看所需的结果 (=0)。现在,也许我改变主意并更喜欢
function otherfunc(x)
disp(cos(x))
end
我再次运行main 并看到1。
我对 Julia 的不了解 如何做完全相同的事情。 我尝试了两种我认为可行的方法。
1)
文件是anotherfunc.jl:
function anotherfunc(x)
print(sin(x))
end
和(在同一目录中)main.jl:
function main()
anotherfunc(0)
end
现在我在终端启动julia并写
julia> include("anotherfunc.jl")
anotherfunc (generic function with 1 method)
julia> include("main.jl")
main (generic function with 1 method)
julia> main()
0.0
很好。现在我将sin 更改为cos 并得到
julia> main()
0.0
这并不让我吃惊,我知道我需要另一个include,即
julia> include("anotherfunc.jl")
anotherfunc (generic function with 1 method)
julia> main()
1.0
所以这可行,但似乎很容易出错,我以后会忘记包含。
2) 我以为我会很聪明并写作
function main
include("anotherfunc.jl")
anotherfunc(0)
end
但是关闭julia并重新启动它会给出
julia> main()
ERROR: MethodError: no method matching anotherfunc(::Int64)
The applicable method may be too new: running in world age 21834, while current world is 21835.
Closest candidates are:
anotherfunc(::Any) at /some/path/anotherfunc.jl:2 (method too new to be called from this world context.)
Stacktrace:
[1] main() at /some/path/main.jl:4
这显然是错误的。
总结:我不知道处理拆分为多个文件的代码和开发过程中的更改的最佳程序。
【问题讨论】:
-
仅供参考,Revise.jl
标签: julia