Interpolate into macro like BenchmarkTools

With @btime it is possible to interpolate values, how can I replicate this in other macros?

julia> x = 8
8

julia> @btime $x
  0.027 ns (0 allocations: 0 bytes)
8

julia> macro fun(expr)
           return esc(expr)
       end
@fun (macro with 1 method)

julia> @fun $x
ERROR: syntax: "$" expression outside quote

The $ thing is specific to BenchmarkTools:

3 Likes