# 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:** 9

<div class="post-metadata">

**Author:** ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)\
**Post date:** [March 17, 2020, 5:06am UTC](https://discourse.julialang.org/t/call-a-macro-within-a-macro/3708/9 "2020-03-17T05:06:46Z")

</div>

With my usual apology to resurrecting a dormant thread, this thread came up high in a google search and I wanted to link it to the more relevant thread:

> [@Calling a macro from within a macro, revisited](https://discourse.julialang.org/t/calling-a-macro-from-within-a-macro-revisited/19680):
>
> Hi all, I have a question: am i seeing a bug in the macro expander, or am I misunderstanding its usage? I’m implementing a macro which delegates (most of) its work to another macro, and I’m running into some issues around escaping. Here is a minimal version which I think should work, based on the discussion in this [related issue](https://discourse.julialang.org/t/call-a-macro-within-a-macro/3708), but isn’t: module Retest using Test macro retestset1(args...) :(@testset($((esc(a) for a in args)...))) # should work? end macro retestset2(args...) esc…

In short, I wanted to call `@show` within a macro, and the seemingly correct macro requires an `esc` around the whole returned expression:

```julia
macro sourceshow(expr)
    si = Base.CoreLogging.@_sourceinfo
    fileline = "$(si[2]):$(si[3])"
    esc(:(begin
        println($fileline)
        @show($expr)
    end
    ))
end

function f()
    y = 4
    @sourceshow y
end

@show macroexpand(Main, :(@sourceshow y))

f()

```

```julia
macro sourceshow(expr)
    si = Base.CoreLogging.@_sourceinfo
    fileline = "$(si[2]):$(si[3])"
    esc(:(begin
        println($fileline)
        @show($expr)
    end
    ))
end

function f()
    y = 4
    @sourceshow y
end

@show macroexpand(Main, :(@sourceshow y))

f()

```

I don’t see any hygiene issues with `@sourceshow`

---

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