Assigning a macro to a variable

We can assign a function to a variable:

julia> f = sin
sin (generic function with 10 methods)

julia> f(1)

Can we do something similar with a macro? For example, I want to do something like this:

julia> using BenchmarkTools

julia> f = btime

julia> @f sin(1)

Not that I know of, but you can

macro f(args...)
    :(@btime($(map(esc, args)...)))

@f 2+2

And it wouldn’t be hard to write a macro to shorten it to @synonym @f = @btime

1 Like

Macros are just functions with a funny name

@eval const $(Symbol("@f")) = $(Symbol("@btime"))