# Re-evaluate function in another module

**URL:** <https://discourse.julialang.org/t/re-evaluate-function-in-another-module/80472>\
**Category:** General Usage\
**Tags:** question, module, namespaces\
**Created:** [May 4, 2022, 10:22am UTC](https://discourse.julialang.org/t/re-evaluate-function-in-another-module/80472 "2022-05-04T10:22:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Post date:** [May 4, 2022, 10:22am UTC](https://discourse.julialang.org/t/re-evaluate-function-in-another-module/80472/1 "2022-05-04T10:22:10Z")

</div>

Consider the following:

```julia
module A
    export foo
    whoami() = "A"
    foo() = whoami()
end

module B
    using Main.A
    whoami() = "B"
end

B.foo() # "A"

```

I understand why that’s the case but is there a way to call `A.foo` “in the context of `B`” i.e. effectively calling `B.whomai()` and returning `"B"`? (short of re-defining `foo` manually in `B`). I tried using `@ __MODULE__ ` in the definition of `foo` but either used it incorrectly or it’s not the right way to go.

The following does part of what I want but I’d like not to modify `A` outside of the scope of `B`.

```julia
module B
    using Main.A;
    import Main.A.whoami
    whoami() = "B"
end

B.foo() # "B" ok 
A.foo() # "B" nok

```

Thanks

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [May 4, 2022, 1:30pm UTC](https://discourse.julialang.org/t/re-evaluate-function-in-another-module/80472/2 "2022-05-04T13:30:56Z")

</div>

Not elegant, but:

```julia
module A
   export foo
   whoami() = @ __MODULE__
   foo = :(eval(:($whoami)))
end 

module B
   # Note that B knows nothing about A
   whoami() = @ __MODULE__
end

A.eval(A.foo)() # Main.A
B.eval(A.foo)() # Main.B
```
