# Interpolate inside a Quote inside a Macro inside a Quote?

**URL:** <https://discourse.julialang.org/t/interpolate-inside-a-quote-inside-a-macro-inside-a-quote/9888>\
**Category:** General Usage\
**Tags:** macros, metaprogramming\
**Created:** [March 22, 2018, 12:47pm UTC](https://discourse.julialang.org/t/interpolate-inside-a-quote-inside-a-macro-inside-a-quote/9888 "2018-03-22T12:47:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [March 22, 2018, 12:47pm UTC](https://discourse.julialang.org/t/interpolate-inside-a-quote-inside-a-macro-inside-a-quote/9888/1 "2018-03-22T12:47:13Z")

</div>

Is it possible to do this? I need this for my package [Reduce.jl](https://github.com/chakravala/Reduce.jl)

Let’s say I have a bunch of functions, call them `fun` and I need a macro for each

```nohighlight
macro fun(expr)
    :(fun($expr))
end

```

But I need to automate this using code generation. So I want to do something like

```nohighlight
for fun in [:name_of_func, :name_of_another_func]
    quote
        macro $fun(expr)
            ## what to put here ?
        end
    end
end

```

Now, so the line of code needs to look like this, but it needs to appear inside the quote:

```nohighlight
julia> :($fun($(Symbol("\$expr"))))
:(func_name($expr))

```

But how can I nest an expression like that inside of a quote?

So the `expr` needs to be interpolated into the output quote of the macro, and all of this needs to happen within a quote block.

Please let me know if it is possible, how to do it. Hopefully, question makes sense to everyone.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 22, 2018, 1:08pm UTC](https://discourse.julialang.org/t/interpolate-inside-a-quote-inside-a-macro-inside-a-quote/9888/2 "2018-03-22T13:08:30Z")

</div>

> [@chakravala](#):
>
> what to put here ?

If you do `q = Expr(:quote, :($fun($(Expr(:$, :expr)))))` and then interpolate `$q` into your macro, that should work, I think?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 22, 2018, 1:36pm UTC](https://discourse.julialang.org/t/interpolate-inside-a-quote-inside-a-macro-inside-a-quote/9888/3 "2018-03-22T13:36:53Z")

</div>

```julia
for fun in [:name_of_func, :name_of_another_func]
    @eval begin
        macro $fun(expr)
            :($$(QuoteNode(fun))($(esc(expr))))
        end
    end
end

```

```julia
julia> @macroexpand @name_of_another_func(bla)
:((Main.name_of_another_func)(bla))

julia> @macroexpand @name_of_func(bla)
:((Main.name_of_func)(bla))

```

maybe

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [March 22, 2018, 3:03pm UTC](https://discourse.julialang.org/t/interpolate-inside-a-quote-inside-a-macro-inside-a-quote/9888/4 "2018-03-22T15:03:00Z")

</div>

Thanks, both worked!
