Using macros to explode a struct into a tuple of its members

You need to escape x inside the macro with esc(x), this is also explained in the manual on macro hygiene:

https://docs.julialang.org/en/v1/manual/metaprogramming/#Hygiene

Note that in this particular example, there is not really a reason to prefer a macro over a regular function. Functions OTOH, are a lot more composable than macros, so it is generally better to avoid macros for things that can be done in a function.

4 Likes