# How can Julia macro take an Expr variable as its arguments?

**URL:** https://discourse.julialang.org/t/how-can-julia-macro-take-an-expr-variable-as-its-arguments/82630
**Category:** New to Julia
**Created:** [June 12, 2022, 11:21am UTC](https://discourse.julialang.org/t/how-can-julia-macro-take-an-expr-variable-as-its-arguments/82630 "2022-06-12T11:21:19Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [June 13, 2022, 8:45pm UTC](https://discourse.julialang.org/t/how-can-julia-macro-take-an-expr-variable-as-its-arguments/82630/4 "2022-06-13T20:45:54Z")

</div>

You can think of it this way. The macro definition you write takes in an expression and returns an expression, much like a method can. But only a method could take in a runtime `Expr` instance and return another. The macro definition is just a way for you to customize one part of a bigger process of parsing and evaluating _source code_. You can’t control the parser converting the source code to an `Expr` that the macro will work on, and you can’t control the macro’s output `Expr` being evaluated. (You can however use `@macroexpand` to wrap the output `Expr` in an extra `Expr` layer so when it is evaluated, you get the output `Expr`.)

This incidentally is why macros are said to only work on literals, symbols, and `Expr` of such; it’s because the _parser_ can only produce such things from source code. However, there is actually an internal (not public API, not stable across versions) [trick](https://discourse.julialang.org/t/is-there-a-trick-to-input-an-expr-into-a-macro/82383/5) to get the macro definition’s underlying method, which _can_ take in runtime `Expr` instances. Right after that trick’s comment in the thread, I also commented how to use the wholly public `macroexpand` function and `$`-interpolation to make a macro work on a runtime `Expr`.

---

_[View the full topic](https://discourse.julialang.org/t/how-can-julia-macro-take-an-expr-variable-as-its-arguments/82630)._
