Find packages by function names

I am taking my first steps with Julia (using version 1.5), I found a nice package and tried to run an example, which was making use of “norm” and “info”.

These functions are not in the default scope, but probably they were in the past. I googled for “norm” and indeed found it is defined in LinearAlgebra, but I could not find the correct package for “info”.

Is there a general approach to find the packages that define a function with a given name?

Many thanks in advance,

The documentation search on JuliaHub is pretty useful for this sort of thing, although info() is such a generic term that it’s hard to search for. The JuliaHub search does turn up the Logging.Logging module in its list, which is the correct answer.

The reason you can’t find info() as a package function is that it used to be a built-in function (in Julia 0.6 and earlier) and was replaced with the @info macro in Julia 0.7, 1.0, and all following versions. It’s possible that the example you’re following is pretty old (before summer of 2018), since it sounds like it’s using pre-1.0 Julia.

By the way, if you have other code that you want to run which was written pre-Julia 1.0, running it in Julia 0.7 can be very helpful. Julia 0.7 has the same functionality as Julia 1.0, but it also has helpful deprecation warnings for behaviors that were removed before 1.0. For example:

Julia 0.7:

julia> norm([1,2,3])
WARNING: Base.norm is deprecated: it has been moved to the standard library package `LinearAlgebra`.
Add `using LinearAlgebra` to your imports.
 in module Main

julia> info("hello world")
┌ Warning: `info()` is deprecated, use `@info` instead.
│   caller = top-level scope at none:0
└ @ Core none:0
INFO: hello world

Thanks a lot, very insightful! The package was updated for 1.0, but the example in the readme was not.

The inverse problem to this, if you have a function already and want to know where it came from, can be solved with @which

julia> @which collect

julia> @which collect(1:10)
collect(r::AbstractRange) in Base at range.jl:997

Similarly you can also load the package you are using and ask it where it got something from.

Referring to it by qualified name of the scope where you find it.

Say I say isposdef being used in the source code of Distributions.jl and i wanted to know where it came from:

julia> using Distributions

julia> @which Distributions.isposdef

julia> methods(Distributions.isposdef)
# 7 methods for generic function "isposdef":
[1] isposdef(D::LinearAlgebra.Diagonal) in LinearAlgebra at /usr/local/src/julia/julia-1.5/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/diagonal.jl:119
[2] isposdef(A::AbstractArray{T,2} where T) in LinearAlgebra at /usr/local/src/julia/julia-1.5/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/dense.jl:91
[3] isposdef(x::Number) in LinearAlgebra at /usr/local/src/julia/julia-1.5/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/dense.jl:93
[4] isposdef(A::Union{LinearAlgebra.Eigen, LinearAlgebra.GeneralizedEigen}) in LinearAlgebra
 at /usr/local/src/julia/julia-1.5/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/eigen.jl:126
[5] isposdef(C::Union{LinearAlgebra.Cholesky, LinearAlgebra.CholeskyPivoted}) in LinearAlgebra at /usr/local/src/julia/julia-1.5/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/cholesky.jl:551
[6] isposdef(J::LinearAlgebra.UniformScaling) in LinearAlgebra at /usr/local/src/julia/julia-1.5/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/uniformscaling.jl:109
[7] isposdef(F::SuiteSparse.CHOLMOD.Factor) in SuiteSparse.CHOLMOD at /usr/local/src/julia/julia-1.5/usr/share/julia/stdlib/v1.5/SuiteSparse/src/cholmod.jl:1812

is also helpful.