How to emit :macro_param in quote in macro?

I’m trying to have a macro output: f(:arg) where arg is passed into the macro. So: @mac1 Blue should emit: f(:Blue).

And more importantly, how would I have found the information in the docs or somewhere?

macro mac1(x)
  blk = quote
    f(:$(esc(x))) # <- how to get that colon to show up?
  end
  return blk
end

QuoteNode(x) rather than esc(x) should do the trick.

This section on quoting Metaprogramming · The Julia Language covers it. The whole metaprogramming page is worth several reads if you’re wanting to implement macros.

2 Likes