在Julia中显示函数的所有方法


9

我如何可以显示所有函数方法在朱莉娅(多分派)?

例如,该函数的名称空间中存在的所有方法abs

Answers:


9

methods函数将返回给定函数的方法表

julia> methods(abs)
# 13 methods for generic function "abs":
[1] abs(a::Pkg.Resolve.FieldValue) in Pkg.Resolve at /home/david/pkg/julia-bin/julia-1.4.0-rc1/share/julia/stdlib/v1.4/Pkg/src/Resolve/fieldvalues.jl:61
[2] abs(a::Pkg.Resolve.VersionWeight) in Pkg.Resolve at /home/david/pkg/julia-bin/julia-1.4.0-rc1/share/julia/stdlib/v1.4/Pkg/src/Resolve/versionweights.jl:36
[3] abs(::Missing) in Base at missing.jl:100
[4] abs(x::Float64) in Base at float.jl:528
...

从Julia 1.4开始,您可以按模块过滤方法表。例如,列出模块abs中定义的方法Dates

julia> methods(abs, Dates)
# 1 method for generic function "abs":
[1] abs(a::T) where T<:Dates.Period in Dates at /home/david/pkg/julia-bin/julia-1.4.0-rc1/share/julia/stdlib/v1.4/Dates/src/periods.jl:95
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.