In Julia, the methods function can be used to retrieve the methods of a function.
julia> f(::Int) = 0 f (generic function with 1 method) julia> f(::String) = "" f (generic function with 2 methods) julia> methods(f)
Macros can also have several methods.
julia> macro g(::Int) 0 end @g (macro with 1 method) julia> macro g(::String) "" end @g (macro with 2 methods) julia> @g 123 0 julia> @g "abc" ""
However, the methods function does not seem to work with macros because Julia first calls the macro because they do not need parentheses.
julia> methods(@g) ERROR: MethodError: no method matching @g() Closest candidates are: @g(::String) at REPL[2]:2 @g(::Int64) at REPL[1]:2
I tried using Expr ession to contain a macro, but that didn't work.
julia> methods(:@g)
How can I get macro methods?
source share