# Module Generation from macros

**URL:** https://discourse.julialang.org/t/module-generation-from-macros/2555
**Category:** General Usage
**Created:** [March 9, 2017, 4:04am UTC](https://discourse.julialang.org/t/module-generation-from-macros/2555 "2017-03-09T04:04:39Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)
#### Post date: [July 30, 2020, 1:59pm UTC](https://discourse.julialang.org/t/module-generation-from-macros/2555/6 "2020-07-30T13:59:56Z")

</div>

Does someone know why the first macro works and the second fails?

```julia
macro mymodule(name)
    modname = esc(name)
    return :(module $modname end)
end
@mymodule MyMod

```

Works. And the second, using a `quote` block does not throwing `ERROR: syntax: "module" expression not at top level` (see also [https://github.com/JuliaLang/julia/issues/1200](https://github.com/JuliaLang/julia/issues/1200)):

```julia
macro mymodule(name)
    modname = esc(name)
    return quote module $modname end end
end
@mymodule MyMod

```

---

_[View the full topic](https://discourse.julialang.org/t/module-generation-from-macros/2555)._
