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
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)
@sandbox (macro with 2 methods)
julia> function sandbox_helper(mod, expr)
@eval $mod begin
sandbox_helper (generic function with 1 method)
julia> @sandbox MyMod begin
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.
Maybe I have to try Revise.jl.
Sorry, I wrote my answer assuming you were using Revise.jl. You should absolutely be using Revise.
Okay. I’ll try Revise.jl and see how it works for me. The Julia document on workflows should probably recommend Revise.
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.
Some quick guidelines on how to use it are here: Modules and Revise · JuliaNotes.jl
That guideline was helpful: Modules and Revise · JuliaNotes.jl. Thanks!
I think it’s much more pleasant to work with the REPL now.
Whether you’re at the REPL or in IJulia, you can typically improve your development experience with Revise
I think that can be considered as recommendation, can’t it?
would be just too categorical for the official documentation - but in most cases one absolutely should.
LOL. How could I miss that? Maybe that section should move to the top
And yup. As I said above, it’s much better now though I have to still restart the REPL sometimes.