gpt4 book ai didi

julia - 如何获取类型的所有方法

转载 作者:行者123 更新时间:2023-12-03 14:44:24 26 4
gpt4 key购买 nike

我有一个T类型,如何在REPL中获取所有专门针对该类型的方法?我的动机是T是在包中定义的,可能很难从源代码中看出我对T的含义。

总而言之,我想要类似

functions(T)


因为 methods已经存在,但是它需要我想了解的功能

最佳答案

您需要使用methodswith(T)

help?> methodswith
search: methodswith

methodswith(typ[, module or function][, showparents])

Return an array of methods with an argument of type typ. If optional showparents
is true, also return arguments with a parent type of typ, excluding type Any.

The optional second argument restricts the search to a particular module or
function.

julia> type Foo end

julia> methodswith(Foo)
0-element Array{Method,1}

julia> foo(::Foo) = nothing
foo (generic function with 1 method)

julia> methodswith(Foo)
1-element Array{Method,1}:
foo(::Foo) at none:1

关于julia - 如何获取类型的所有方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38564357/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com