我正在编写一个 julia 代码,其中有几个文件,并从这些文件调用函数到一个名为 的主函数run.jl。每次我对这些文件中的任何一个进行更改时,我都需要重新启动 Julia REPL,这有点烦人。无论如何要解决这个问题。例如
# --------------------------------- run.jl
include("agent_types.jl")
include("resc_funcs.jl")
using .AgentTypes: Cas, Resc
using .RescFuncs: update_rescuers_at_pma!, travel_to_loc
# ... some code
for i = 1:500
update_rescuers_at_pma!(model)
travel_to_loc(model)
end
# ------------------------------ resc_funcs.jl
function travel_to_loc(model)
println(get_resc_by_prop(model, :on_way_to_iz))
for resc_id in get_resc_by_prop(model,:on_way_to_iz)
push!(model[resc_id].dist_traject, model[resc_id].dist_to_agent) #This is just for checking purposes
model[resc_id].dist_to_agent -= model.dist_per_step
push!(model[resc_id].loc_traject, "on_way_to_iz")
end
#If we add new print statement here and execute run.jl it wont print
println(model[resc_id].loc_traject) #new amendment to code
end
Run Code Online (Sandbox Code Playgroud)
但现在当我去更新travel_to_loc功能时。在反映这些更改之前,我需要重新启动 Julia repl。我想知道在保存文件(在本例中为 resc_funcs.jl)后是否有办法在执行run.jl.
最简单的工作流程可能如下:
cd()Julia 的命令)MyMod.jl
module MyMod
export f1
function f1(x)
x+1
end
end
Run Code Online (Sandbox Code Playgroud)
LOAD_PATH并加载Revise.jl
push!(LOAD_PATH, ".")
using Revise
Run Code Online (Sandbox Code Playgroud)
julia> using MyMod
[ Info: Precompiling MyMod [top-level]
julia> f1(3)
4
Run Code Online (Sandbox Code Playgroud)
x+1x+3julia> f1(3)
6
Run Code Online (Sandbox Code Playgroud)
笔记:
struct当数据结构发生变化时(修改对象的定义),您仍然需要重新启动 REPLPkg.generate,但我想让事情变得简单。| 归档时间: |
|
| 查看次数: |
649 次 |
| 最近记录: |