Reputation: 3828
I am working on a julia code where I have several files and call functions from these files to a main function called run.jl
. Every time I make changes to any one of these files I need to restart the julia REPL which is a bit annoying. Anyway to work around this.
For example
# --------------------------------- 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
But now when I go and update travel_to_loc
function for example. I need to restart the julia repl before those changes are reflected. I am wondering if there is a way after you save the file (resc_funcs.jl in this case) those amendments are reflected when you execute run.jl
.
Upvotes: 1
Views: 907
Reputation: 42214
The simplest workflow could be the following:
cd()
command from Julia)MyMod.jl
module MyMod
export f1
function f1(x)
x+1
end
end
LOAD_PATH
and load Revise.jl
push!(LOAD_PATH, ".")
using Revise
julia> using MyMod
[ Info: Precompiling MyMod [top-level]
julia> f1(3)
4
x+1
to x+3
julia> f1(3)
6
Notes:
struct
object)Pkg.generate
but I wanted to make things simplified.Upvotes: 5