Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Julia 获取函数签名_Julia - Fatal编程技术网

Julia 获取函数签名

Julia 获取函数签名,julia,Julia,有没有办法在运行时获取函数的签名?我想在调用该函数之前检查签名。比如: exp = @sig func if "kw" ∈ string(exp) func(kw=value) end 如我在评论中所述,我认为您正在Julia 1.1中寻找方法(func),可以通过以下方式获得签名: julia> function test(a::Integer, b::Integer, c::Integer) end test (generic function with 2 met

有没有办法在运行时获取函数的签名?我想在调用该函数之前检查签名。比如:

exp = @sig func
if "kw" ∈ string(exp)
  func(kw=value)
end

如我在评论中所述,我认为您正在Julia 1.1中寻找
方法(func)

,可以通过以下方式获得签名:

julia> function test(a::Integer, b::Integer, c::Integer)
       end
test (generic function with 2 methods)
julia> function extractSig(x) methods(x).ms[1].sig end
julia> extractSig(test)
Tuple{typeof(test),Integer,Integer,Integer}
如果需要签名符号,则以下基本函数在Julia 1.1中就足够了,即

Base.method_argnames(methods(x).ms[1])

值得注意的是,上面的代码只考虑函数的第一个定义。可能会有更多重载定义

方法(func)
?非常感谢您的快速回答!它工作得很好。