# Why can't I define a macro within a macro and call it?

**URL:** <https://discourse.julialang.org/t/why-cant-i-define-a-macro-within-a-macro-and-call-it/31025>\
**Category:** General Usage\
**Created:** [November 13, 2019, 1:05am UTC](https://discourse.julialang.org/t/why-cant-i-define-a-macro-within-a-macro-and-call-it/31025 "2019-11-13T01:05:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [November 13, 2019, 1:05am UTC](https://discourse.julialang.org/t/why-cant-i-define-a-macro-within-a-macro-and-call-it/31025/1 "2019-11-13T01:05:54Z")

</div>

```julia
macro mm(T)
           quote
               macro kk()
                   :(println("A")) |> esc
               end
               @kk
           end |> esc
       end

```

julia\> @macroexpand @mm Int  
ERROR: LoadError: UndefVarError: @kk not defined  
Stacktrace:  
[1] top-level scope  
[2] #macroexpand#32 at ./expr.jl:107 [inlined]  
[3] (::getfield(Base, Symbol(“#kw##macroexpand”)))(::NamedTuple{(:recursive,),Tuple{Bool}}, ::typeof(macroexpand), ::Module, ::Expr) at ./none:0  
[4] top-level scope at REPL[11]:1  
in expression starting at REPL[10]:6

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [November 13, 2019, 2:14am UTC](https://discourse.julialang.org/t/why-cant-i-define-a-macro-within-a-macro-and-call-it/31025/2 "2019-11-13T02:14:43Z")

</div>

Because the macro needed to be defined in order for the code to be lowered. Therefore, your resulting code must be evaluated first before it can be lowered and evaluated and that’s impossible.

Why do you want to do this.
