3

How to seek a concrete function in Julia? lookfor would make it in Matlab / GNU Octave, how can it be done here?

nightcod3r
  • 752
  • 1
  • 7
  • 26
  • MATLAB’s `lookfor` was great in the times before Google and online documentation. It is totally obsolete now. Online documentation allows for much better search and discovery. Use it! – Cris Luengo May 14 '21 at 13:34

2 Answers2

9

The equivalent of lookfor is 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

Other useful functions, depending on what you're looking for, include methodswith, which can give you a list of methods that are specified for a particular argument type:

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                                  
 ...   
Fengyang Wang
  • 11,901
  • 2
  • 38
  • 67
  • @ nightcod3r: note that `apropos`, like `lookfor` will not detect functions from packages that haven't been loaded. So it might be useful to google regardless: a nice way of going straight to official documentation / package pages is searching for `fourier transform site:julialang.org` – Tasos Papastylianou Sep 23 '16 at 17:29
  • you're right @TasosPapastylianou, in the end it's all about googling. – nightcod3r Sep 23 '16 at 21:47
0

A comment on Fengyang's great answer. Notice the difference between searching at the Julia prompt with apropos("first") vs typing a question mark and the word ?first.

As you type the question mark, the prompt changes to a question mark. If you type "first", this is equivalent to the above (with less typing). If you type first without quote-marks, you get a search over the variables that are exported by the modules currently loaded.

Illustration:

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

If you search for a string, case is ignored. If you want to search within the DataFrames module, type using DataFrames before searching.

PatrickT
  • 10,037
  • 9
  • 76
  • 111
  • See also my question/answer here: https://stackoverflow.com/questions/67527985/julias-equivalent-to-rs-double-question-mark-help-search/ – PatrickT May 14 '21 at 01:35