Coming from Common Lisp, using the Julia REPL is… well… frustrating. There’s no easy way to send a piece of code from a file to the REPL with its module namespace correctly recognized. I read https://docs.julialang.org/en/v1/manual/workflow-tips/#REPL-based-workflow, but it doesn’t really work as I want it to be. For example, while I’m working on a file a few steps deep into a module subtree, I want to reload just that part of the code (or file) into the REPL with its module namespace correctly recognized by the REPL. But the current REPL doesn’t seem to have that functionality. With its current functionality, I don’t see any improvements over just running the script from a terminal after code modifications.
The VSCode extension seems to improve this a little bit but not that much. I know about web-based workflows like Jupyter and Pluto. They are great for live documents and visualization, but I want to use the editor and the REPL for my regular coding.
Maybe I’m missing something. Does anyone have a good REPL-based workflow?
Maybe I do not understand exactly the nature of your problem, but Juno, VSCode, Emacs and Vim all have capabilities to send piece code to REPL and execute it their. Regarding reload, there is Revise.jl which do it automatically.
I wrote small video of the process, sorry for quality, it’s hard to make it good without rehearsal.
This is a pain point I empathize with. I agree this isn’t as easy as it could (or should) be. There are a few solutions
Use Exfiltrator.jl and @exfiltrate to pass code in and out of a function
Use Reexport so that dependency packages are exported, then have this somewhat problematic code in your module
# Export everything for convenience
for n in names(@__MODULE__; all=true)
if Base.isidentifier(n) && n ∉ (Symbol(@__MODULE__), :eval, :include)
@eval export $n
end
end
This will export everything you create in your module. Some times it doesn’t update with Revise though, but you can just copy and paste it with the @__MODULE__ replaced and it will work.
You can use this macro I just came up with (and have not vetted)
julia> macro sandbox(mod, expr)
esc(sandbox_helper(mod, expr))
end
@sandbox (macro with 2 methods)
julia> function sandbox_helper(mod, expr)
quote
@eval $mod begin
let
$expr
end
end
end
end
sandbox_helper (generic function with 1 method)
julia> @sandbox MyMod begin
foo()
end
1
cc @Mason as I think he would be interested in this.
Let’s say I have MyPkg.jl and it includes another file sub1.jl. After I update sub1.jl, if I want to reload the code into the REPL, I have to go back to my “driver” file and reload that file from VSCode. If I just reload the sub1.jl file, the code goes to the Main module instead of MyPkg, which is not what I want.
Indeed, Revise is a central tool now. There are plans to make in the default distribution. With it you won’t even have to “send” the code anymore to the REPL.