在Julia中是否有类似Octave的“lookfor”命令的等效命令?

3
如何在Julia中查找具体函数?在Matlab / GNU Octave中,可以使用lookfor实现,那么在这里应该如何操作?

MATLAB的lookfor在Google和在线文档出现之前是非常好用的。但现在它已经完全过时了。在线文档可以提供更好的搜索和发现功能。请使用它! - Cris Luengo
2个回答

9

lookfor的等价命令是apropos

julia> apropos("fourier transform")
Base.DFT.fft

julia> apropos("concatenate")
Base.:*
Base.hcat
Base.cat
Base.flatten
Base.mapslices
Base.vcat
Base.hvcat
Base.SparseArrays.blkdiag
Core.@doc

其他有用的函数取决于你要查找的内容,包括methodswith,它可以给出针对特定参数类型指定的方法列表:

julia> methodswith(Regex)
25-element Array{Method,1}:
 ==(a::Regex, b::Regex) at regex.jl:370                                                                
 apropos(io::IO, needle::Regex) at docs/utils.jl:397                                                   
 eachmatch(re::Regex, str::AbstractString) at regex.jl:365                                             
 eachmatch(re::Regex, str::AbstractString, ovr::Bool) at regex.jl:362                                  
 ...   

@nightcod3r:请注意,像 lookfor 一样,apropos 不会检测未加载包中的函数。因此,无论如何搜索都可能很有用:一个很好的方式是直接搜索官方文档/包页面,例如搜索 fourier transform site:julialang.org - Tasos Papastylianou
你说得对,@TasosPapastylianou,在最后,一切都是关于谷歌搜索。 - nightcod3r

0
关于Fengyang的好答案的评论。请注意在Julia提示符下使用apropos("first")搜索与键入问号和单词?first之间的区别。
当您键入问号时,提示符会变成问号。如果您键入"first",这相当于上面的操作(少打几个字)。如果您键入first 不带引号,您将获得对当前加载的模块导出的变量进行搜索的结果。
举例说明:
help?>"first"
Base.ExponentialBackOff
Base.moduleroot
...  # rest of the output removed


help?>first 
search: first firstindex popfirst! pushfirst! uppercasefirst lowercasefirst

  first(coll)

  Get the first element of an iterable collection. Return the start point of
  an AbstractRange even if it is empty.
  ...  # rest of the output removed

如果你搜索一个字符串,大小写将被忽略。如果你想在 DataFrames 模块中搜索,请在搜索之前输入 using DataFrames


请参见我的问题/答案:https://dev59.com/D8Dqa4cB1Zd3GeqPi61Z - PatrickT

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接