Get the argument names of an function

A hint is that Julia itself can print the arguments. So step into show with the debugger:

julia> using Debugger

julia> function f(x,y::Integer,z=3)   # just for fun, add a type parameter
           p = x+y*z
           return p 
       end
f (generic function with 4 methods)

julia> m = first(methods(f))
f(x, y::Integer) in Main at REPL[5]:2

julia> @enter show(m)
In show(x) at show.jl:325
>325  show(x) = show(stdout::IO, x)

About to run: (typeassert)(Base.TTY(RawFD(0x0000000d) open, 0 bytes waiting), IO)
1|debug> se
In show(x) at show.jl:325
>325  show(x) = show(stdout::IO, x)

About to run: (show)(Base.TTY(RawFD(0x0000000d) open, 0 bytes waiting), f(x, y::Integer) in Main at REPL[5]:2)
1|debug> s
In #show#393(kwtype, , io, m) at methodshow.jl:159
 158  function show(io::IO, m::Method; kwtype::Union{DataType, Nothing}=nothing)
>159      tv, decls, file, line = arg_decl_parts(m)
 160      sig = unwrap_unionall(m.sig)
 161      ft0 = sig.parameters[1]
 162      ft = unwrap_unionall(ft0)
 163      d1 = decls[1]

About to run: Core.NewvarNode(:(_15))
1|debug> n
In #show#393(kwtype, , io, m) at methodshow.jl:159
 158  function show(io::IO, m::Method; kwtype::Union{DataType, Nothing}=nothing)
 159      tv, decls, file, line = arg_decl_parts(m)
>160      sig = unwrap_unionall(m.sig)
 161      ft0 = sig.parameters[1]
 162      ft = unwrap_unionall(ft0)
 163      d1 = decls[1]
 164      if sig === Tuple

About to run: (getproperty)(f(x, y::Integer) in Main at REPL[5]:2, :sig)
1|julia> decls
3-element Array{Tuple{String,String},1}:
 ("", "typeof(f)")
 ("x", "")        
 ("y", "Integer") 
6 Likes