Escaping in a macro

Not just that. "" is a literal and in general, any expressions could be interpolated some will need ().

Any value can take place of a in $a, including "...". This is not a separate construct. I prefer $("...") though for readability, but ()s are optional.

Thank all of you! I learned (which are not in the documentation):

  1. Interpolation of expressions sometimes does not need parentheses, other times it does.
  2. esc() can occur anywhere in a macro, not just in the context of a return expression.
  3. Macros are more tricky than what you expect.

I try to remember…

This is open source, and open source only improves through the work of its contributors. The single most effective thing you can do to make Julia’s macro documentation better is to open a pull request with suggestions for changes or improvements. The only barrier to being a contributor to Julia itself is the willingness to do so.

6 Likes

There was a workshop titled “A Practical Introduction to Metaprogramming in Julia” At this year’s JuliaCon. Find it on YouTube at:

I haven’t watched it (it’s on my to-do list) so I can’t vouch for its quality but it might be a good resource that compliments the manual.

Actually it doesn’t talk about macros at all but is well worth watching for its insights into how Julia operates behind the scenes.

1 Like