# Differences of Core.eval vs. running the code directly in other modules then Main

**URL:** <https://discourse.julialang.org/t/differences-of-core-eval-vs-running-the-code-directly-in-other-modules-then-main/82489>\
**Category:** General Usage\
**Tags:** documenter, metaprogramming, eval, modules\
**Created:** [June 9, 2022, 11:19am UTC](https://discourse.julialang.org/t/differences-of-core-eval-vs-running-the-code-directly-in-other-modules-then-main/82489 "2022-06-09T11:19:52Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [June 9, 2022, 9:27pm UTC](https://discourse.julialang.org/t/differences-of-core-eval-vs-running-the-code-directly-in-other-modules-then-main/82489/5 "2022-06-09T21:27:47Z")

</div>

> [@sfuerst](#):
>
> I do not understand, why the binding is necessary

I don’t know the internals, but it seems to me that separating the creation of a module (which needs a fixed name) and the binding to another module’s namespace (possibly with another name) may be necessary to allow things like this:

```julia
julia> import Random as RNDM # I might want `Main.Random` to be a different thing

julia> @isdefined Random
false

julia> RNDM.eval(:@ __MODULE__ ) # But this is the "real" name of the module
Random

```

With `Module(:Sandbox)` you are creating the module called `Sandbox`, but still have the possibility of using `Main.Sandbox` for a different thing, as in the previous example with the module `Random`.

> [@sfuerst](#):
>
> why it’s not enough to bind it to a function local variable

I don’t know the answer to that, but I had never seen a module defined as a local object of a function - I didn’t even imagine that it could be allowed.

You comment that this is related to Documenter.jl, whose internals I don’t know, so that may be the reason of my failure to understand what you are trying to do. Could this other topic be related to the problem you report?

> [@Pass local module to a function?](https://discourse.julialang.org/t/pass-local-module-to-a-function/40021):
>
> I’m trying to create a minimal working example of a Documenter error I’m experiencing. However I’m having trouble passing the “local” module to the doctest function, This is what I’m trying: using Documenter module Foo function foo() end end doctest(Foo) I’ve also tried “.Foo”, “…Foo”, “…Foo”, and “Main.Foo”. Is this even possible? Or do I need to create a module somewhere and use Pkg to add it?

---

_[View the full topic](https://discourse.julialang.org/t/differences-of-core-eval-vs-running-the-code-directly-in-other-modules-then-main/82489)._
