# Call a macro within a macro

**URL:** <https://discourse.julialang.org/t/call-a-macro-within-a-macro/3708>\
**Category:** General Usage\
**Created:** [May 14, 2017, 5:04pm UTC](https://discourse.julialang.org/t/call-a-macro-within-a-macro/3708 "2017-05-14T17:04:47Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![findmyway](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/findmyway/32/4946_2.png) [@findmyway](https://discourse.julialang.org/u/findmyway)\
**Post date:** [June 23, 2018, 8:23am UTC](https://discourse.julialang.org/t/call-a-macro-within-a-macro/3708/6 "2018-06-23T08:23:24Z")

</div>

Hi @yuyichao , @kristoffer.carlsson

I just encounter a similar problem.

To make it simple:

I have a inner macro:

```julia
macro m1(ex) :(println($ex + 1)) end

```

and an outer macro:

```julia
macro m2(ex) :(@m1 $(esc(ex))) end

```

But

```julia
julia> for i in 1:3
       @m2 i
       end
ERROR: UndefVarError: i not defined
Stacktrace:
 [1] macro expansion at ./REPL[10]:2 [inlined]
 [2] top-level scope at ./<missing>:0

```

How can the inner macro access `i`?

Thanks.

---

_[View the full topic](https://discourse.julialang.org/t/call-a-macro-within-a-macro/3708)._
