# Is there a way to replace a "top-level" module in a running session?

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-replace-a-top-level-module-in-a-running-session/28521>\
**Category:** Juno\
**Created:** [September 7, 2019, 10:31pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-replace-a-top-level-module-in-a-running-session/28521 "2019-09-07T22:31:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [September 7, 2019, 10:31pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-replace-a-top-level-module-in-a-running-session/28521/1 "2019-09-07T22:31:07Z")

</div>

The way I usually use Juno for package development is that I open up the main `Foo.jl` file for my project `Foo`, select all, and evaluate. This gives me a `Main.Foo` module. I then go around to different files included from `Foo.jl`, do a “change module” to `Main.Foo` and edit / evaluate things inside of them.

I’m aware I could just do `using Foo`, and then edit / evaluate things in the various files with the module set to just `Foo` instead of `Main.Foo` (which is nice since the module is automatically detected in that case), but the problem is, what if I need to completely re-evaluate / replace the “top-level” module `Foo`, like I’d need to do if e.g. I changed the layout of a struct? Is there a way to do so with Juno that I’m not aware of?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 8, 2019, 7:09am UTC](https://discourse.julialang.org/t/is-there-a-way-to-replace-a-top-level-module-in-a-running-session/28521/2 "2019-09-08T07:09:58Z")

</div>

[https://github.com/JuliaLang/julia/issues/22562](https://github.com/JuliaLang/julia/issues/22562) for some comments and  
[https://github.com/JuliaLang/julia/pull/33102](https://github.com/JuliaLang/julia/pull/33102) for a PR.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [September 8, 2019, 7:08pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-replace-a-top-level-module-in-a-running-session/28521/3 "2019-09-08T19:08:41Z")

</div>

Thanks, although I may be missing something. Those look like a way to evaluate code in an arbitrary module, which Juno already does and I use a lot (and having that PR would be great to do it at the REPL easily too). My question was if you can swap out a top-level module, e.g. swap in a new version of `Foo` after you’ve already done a `using Foo`?

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [September 9, 2019, 4:15am UTC](https://discourse.julialang.org/t/is-there-a-way-to-replace-a-top-level-module-in-a-running-session/28521/4 "2019-09-09T04:15:43Z")

</div>

Maybe u r talking about Revise which is a God send

```julia
using Revise
using Foo

#just use Foo and every time u update it, all functions will be updated. So no need to select everything and run

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 9, 2019, 6:09am UTC](https://discourse.julialang.org/t/is-there-a-way-to-replace-a-top-level-module-in-a-running-session/28521/5 "2019-09-09T06:09:18Z")

</div>

> [@marius311](#):
>
> My question was if you can swap out a top-level module, e.g. swap in a new version of `Foo` after you’ve already done a `using Foo` ?

Oh, I missunderstood then.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [September 9, 2019, 7:41am UTC](https://discourse.julialang.org/t/is-there-a-way-to-replace-a-top-level-module-in-a-running-session/28521/6 "2019-09-09T07:41:20Z")

</div>

Juno doesn’t support that use case atm, but I _think_ it could emulate the package loading mechanism (maybe even automatically if you eval a file which looks like it is a package’s entry point).

That said, just evaluating the `module` expression in the right context (aka whatever module you want to use the package in) will usually work just fine – the only complication is that you might need to `pkg> activate` the right environment first.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [September 9, 2019, 7:45am UTC](https://discourse.julialang.org/t/is-there-a-way-to-replace-a-top-level-module-in-a-running-session/28521/7 "2019-09-09T07:45:21Z")

</div>

Thanks for the confirmation. And just to make sure I’m not missing anything, but another complication is that I have to “change module” to `Main.Foo` in all my included files, right? (since they’re autodetected as `Foo`, which is different than `Main.Foo`).

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [September 9, 2019, 9:47am UTC](https://discourse.julialang.org/t/is-there-a-way-to-replace-a-top-level-module-in-a-running-session/28521/8 "2019-09-09T09:47:12Z")

</div>

Ah, right, good point. That seems really annoying.  
Wanna open an issue about replacing top-level modules just so we don’t forget about it?
