# REPL-based workflow

**URL:** <https://discourse.julialang.org/t/repl-based-workflow/57629>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 20, 2021, 10:07pm UTC](https://discourse.julialang.org/t/repl-based-workflow/57629 "2021-03-20T22:07:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaydub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaydub/32/23130_2.png) [@jaydub](https://discourse.julialang.org/u/jaydub)\
**Post date:** [March 20, 2021, 10:07pm UTC](https://discourse.julialang.org/t/repl-based-workflow/57629/1 "2021-03-20T22:07:50Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [March 20, 2021, 10:21pm UTC](https://discourse.julialang.org/t/repl-based-workflow/57629/2 "2021-03-20T22:21:10Z")

</div>

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.

[https://asciinema.org/a/zt311WEOur8AMGtHW4cN9bGoo](https://asciinema.org/a/zt311WEOur8AMGtHW4cN9bGoo)

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [March 20, 2021, 10:25pm UTC](https://discourse.julialang.org/t/repl-based-workflow/57629/3 "2021-03-20T22:25:41Z")

</div>

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

1. Use Exfiltrator.jl and `@exfiltrate` to pass code in and out of a function
2. Use Reexport so that dependency packages are exported, then have this somewhat problematic code in your module

```julia
# 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.

1. You can use this macro I just came up with (and have not vetted)

```julia
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.

---

<div class="post-metadata">

**Author:** ![jaydub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaydub/32/23130_2.png) [@jaydub](https://discourse.julialang.org/u/jaydub)\
**Post date:** [March 20, 2021, 10:33pm UTC](https://discourse.julialang.org/t/repl-based-workflow/57629/4 "2021-03-20T22:33:54Z")

</div>

Let’s say I have MyPkg.jl and it `include`s 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.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [March 20, 2021, 10:35pm UTC](https://discourse.julialang.org/t/repl-based-workflow/57629/5 "2021-03-20T22:35:25Z")

</div>

Sorry, I wrote my answer assuming you were using Revise.jl. You should absolutely be using Revise.

---

<div class="post-metadata">

**Author:** ![jaydub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaydub/32/23130_2.png) [@jaydub](https://discourse.julialang.org/u/jaydub)\
**Post date:** [March 20, 2021, 10:41pm UTC](https://discourse.julialang.org/t/repl-based-workflow/57629/6 "2021-03-20T22:41:13Z")

</div>

Okay. I’ll try Revise.jl and see how it works for me. The Julia document on [workflows](https://docs.julialang.org/en/v1/manual/workflow-tips) should probably recommend Revise.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [March 20, 2021, 10:58pm UTC](https://discourse.julialang.org/t/repl-based-workflow/57629/7 "2021-03-20T22:58:54Z")

</div>

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](https://m3g.github.io/JuliaNotes.jl/stable/modules/)

---

<div class="post-metadata">

**Author:** ![jaydub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaydub/32/23130_2.png) [@jaydub](https://discourse.julialang.org/u/jaydub)\
**Post date:** [March 21, 2021, 1:45am UTC](https://discourse.julialang.org/t/repl-based-workflow/57629/8 "2021-03-21T01:45:16Z")

</div>

That guideline was helpful: [Modules and Revise · JuliaNotes.jl](https://m3g.github.io/JuliaNotes.jl/stable/modules/). Thanks!

I think it’s much more pleasant to work with the REPL now.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [March 21, 2021, 1:06pm UTC](https://discourse.julialang.org/t/repl-based-workflow/57629/9 "2021-03-21T13:06:03Z")

</div>

> [@jaydub](#):
>
> The Julia document on [workflows](https://docs.julialang.org/en/v1/manual/workflow-tips) should probably recommend Revise.

> [Whether you’re at the REPL or in IJulia, you can typically improve your development experience with Revise](https://docs.julialang.org/en/v1/manual/workflow-tips/#Revise-based-workflows)

I think that can be considered as recommendation, can’t it? 😉

> [@pdeffebach](#):
>
> You should absolutely be using Revise.

would be just too categorical for the official documentation - but in most cases one absolutely should.

---

<div class="post-metadata">

**Author:** ![jaydub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaydub/32/23130_2.png) [@jaydub](https://discourse.julialang.org/u/jaydub)\
**Post date:** [March 21, 2021, 3:48pm UTC](https://discourse.julialang.org/t/repl-based-workflow/57629/10 "2021-03-21T15:48:38Z")

</div>

> [@Eben60](#):
>
> > [Whether you’re at the REPL or in IJulia, you can typically improve your development experience with Revise](https://docs.julialang.org/en/v1/manual/workflow-tips/#Revise-based-workflows)
> 
> I think that can be considered as recommendation, can’t it? 😉

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.
