# Functions with independent (global) scopes

**URL:** https://discourse.julialang.org/t/functions-with-independent-global-scopes/103703
**Category:** General Usage
**Created:** [September 9, 2023, 2:51pm UTC](https://discourse.julialang.org/t/functions-with-independent-global-scopes/103703 "2023-09-09T14:51:39Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [September 10, 2023, 6:33am UTC](https://discourse.julialang.org/t/functions-with-independent-global-scopes/103703/9 "2023-09-10T06:33:18Z")

</div>

Regarding a function named main, see [(on hold): If you have a function called `main`, you may need to tweak it](https://discourse.julialang.org/t/on-hold-if-you-have-a-function-called-main-you-may-need-to-tweak-it/103519)

You may be interested in the contextual module REPL introduced in Julia 1.9. This lets you change the module from `Main` to an arbitrary module, effectively changing your global scope.

> **[Julia 1.9 Highlights](https://julialang.org/blog/2023/04/julia-1.9-highlights/#contextual_module_repl)**
>
> Highlights of the Julia 1.9 release.

[https://docs.julialang.org/en/v1/stdlib/REPL/#Changing-the-contextual-module-which-is-active-at-the-REPL](https://docs.julialang.org/en/v1/stdlib/REPL/#Changing-the-contextual-module-which-is-active-at-the-REPL)

Julia modules are a top level encapsulation. I believe you can effectively accomplish your goals by changing the module context.

Here is a verbose demonstration.

```julia
julia> x = 5
5

julia> varinfo()
  name size summary
  –––––––––––––––– ––––––––––– –––––––
  Base Module
  Core Module
  InteractiveUtils 529.576 KiB Module
  Main Module
  ans 8 bytes Int64                      
  x 8 bytes Int64
                                                        
julia> using REPL

julia> module Foo end
Main.Foo                                                
julia> REPL.activate(Foo)
                                                        
(Main.Foo) julia> varinfo()
  name size summary
  –––– –––– –––––––
  Foo Module

(Main.Foo) julia> x
ERROR: UndefVarError: `x` not defined

(Main.Foo) julia> x = 6
6

(Main.Foo) julia> x
6

(Main.Foo) julia> using ..REPL

(Main.Foo) julia> REPL.activate()

julia> x
5

julia> Foo.x
6

```

---

_[View the full topic](https://discourse.julialang.org/t/functions-with-independent-global-scopes/103703)._
