If you have a working call for the function, you can use @less
or @edit
to see the source code. For example spy
must be called with a matrix, so you can do @less spy([1 2; 3 4])
.
If you just want to see the file and line number (not the source), you can use @which
:
julia> @which spy([1 2; 3 4])
spy(M::AbstractMatrix{T} where T, elements::Union{Function, Gadfly.Element, Theme, Type}...; mapping...) in Gadfly at /home/j/.julia/packages/Gadfly/nN3lf/src/poetry.jl:135
(You can also use @which spy
to see in which module the function is defined.)
In the two cases above, you must write a complete function call with parameters. This way, Julia can find the definition of the method you want (which depends on the type of the parameters).
If you don’t know how to call spy
, or if you want to find the definitions of all methods (for all types of parameters), use methods
:
julia> methods(spy)
# 1 method for generic function "spy":
[1] spy(M::AbstractMatrix{T} where T, elements::Union{Function, Gadfly.Element, Theme, Type}...; mapping...) in Gadfly at /home/j/.julia/packages/Gadfly/nN3lf/src/poetry.jl:135
Here there is only one method, but for the example the filter
function has many methods:
julia> methods(filter)
# 12 methods for generic function "filter":
[1] filter(f, t::Tuple{Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Vararg{Any, N}} where N) in Base at tuple.jl:345
[2] filter(f, xs::Tuple) in Base at tuple.jl:342
[3] filter(f, a::Array{T, N}) where {T, N} in Base at array.jl:2502
[4] filter(f, d::AbstractDict) in Base at abstractdict.jl:429
[5] filter(f, Bs::BitArray) in Base at bitarray.jl:1748
[6] filter(f, a::AbstractArray) in Base at array.jl:2514
[7] filter(pred, s::AbstractSet) in Base at abstractset.jl:414
[8] filter(f, s::Union{SubString{String}, String}) in Base at strings/substring.jl:242
[9] filter(f, s::AbstractString) in Base at strings/basic.jl:622
[10] filter(f, itr::Base.SkipMissing{var"#s832"} where var"#s832"<:AbstractArray) in Base at missing.jl:381
[11] filter(f::Function, l::DataStructures.MutableLinkedList{T}) where T in DataStructures at /home/j/.julia/packages/DataStructures/ixwFs/src/mutable_list.jl:92
[12] filter(f::Function, l::DataStructures.LinkedList{T}) where T in DataStructures at /home/j/.julia/packages/DataStructures/ixwFs/src/list.jl:81
And the package DataFrames.jl for example defines many more methods for filter
, so if I execute using DataFrames; methods(filter)
I see yet more results:
julia> using DataFrames
julia> methods(filter)
# 23 methods for generic function "filter":
[1] filter(f, t::Tuple{Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Vararg{Any, N}} where N) in Base at tuple.jl:345
[2] filter(f, xs::Tuple) in Base at tuple.jl:342
[3] filter(f, a::Array{T, N}) where {T, N} in Base at array.jl:2502
[4] filter(f, d::AbstractDict) in Base at abstractdict.jl:429
[5] filter(f, Bs::BitArray) in Base at bitarray.jl:1748
[6] filter(f, a::AbstractArray) in Base at array.jl:2514
[7] filter(pred, s::AbstractSet) in Base at abstractset.jl:414
[8] filter(f, s::Union{SubString{String}, String}) in Base at strings/substring.jl:242
[9] filter(f, s::AbstractString) in Base at strings/basic.jl:622
[10] filter(f, itr::Base.SkipMissing{var"#s832"} where var"#s832"<:AbstractArray) in Base at missing.jl:381
[11] filter(f::Function, l::DataStructures.MutableLinkedList{T}) where T in DataStructures at /home/j/.julia/packages/DataStructures/ixwFs/src/mutable_list.jl:92
[12] filter(f::Function, l::DataStructures.LinkedList{T}) where T in DataStructures at /home/j/.julia/packages/DataStructures/ixwFs/src/list.jl:81
[13] filter(::Pair{var"#s266", B} where {var"#s266"<:AsTable, B}, gdf::GroupedDataFrame) in DataFrames at /home/j/.julia/packages/DataFrames/zXEKU/src/groupeddataframe/groupeddataframe.jl:928
[14] filter(::Pair{var"#s266", B} where {var"#s266"<:AbstractVector{Int64}, B}, gdf::GroupedDataFrame) in DataFrames at /home/j/.julia/packages/DataFrames/zXEKU/src/groupeddataframe/groupeddataframe.jl:911
[15] filter(::Pair{var"#s266", B} where {var"#s266"<:(AbstractVector{var"#s164"} where var"#s164"<:AbstractString), B}, gdf::GroupedDataFrame) in DataFrames at /home/j/.julia/packages/DataFrames/zXEKU/src/groupeddataframe/groupeddataframe.jl:907
[16] filter(::Pair{var"#s266", B} where {var"#s266"<:AbstractVector{Symbol}, B}, gdf::GroupedDataFrame) in DataFrames at /home/j/.julia/packages/DataFrames/zXEKU/src/groupeddataframe/groupeddataframe.jl:905
[17] filter(::Pair{var"#s266", B} where {var"#s266"<:Union{AbstractString, Signed, Symbol, Unsigned}, B}, gdf::GroupedDataFrame) in DataFrames at /home/j/.julia/packages/DataFrames/zXEKU/src/groupeddataframe/groupeddataframe.jl:903
[18] filter(::Pair, gdf::GroupedDataFrame) in DataFrames at /home/j/.julia/packages/DataFrames/zXEKU/src/groupeddataframe/groupeddataframe.jl:909
[19] filter(f, gdf::GroupedDataFrame) in DataFrames at /home/j/.julia/packages/DataFrames/zXEKU/src/groupeddataframe/groupeddataframe.jl:901
[20] filter(::Pair{var"#s23", B} where {var"#s23"<:AsTable, B}, df::AbstractDataFrame; view) in DataFrames at /home/j/.julia/packages/DataFrames/zXEKU/src/abstractdataframe/abstractdataframe.jl:1026
[21] filter(::Pair{var"#s20", B} where {var"#s20"<:Union{AbstractVector{var"#s19"} where var"#s19"<:Integer, AbstractVector{var"#s18"} where var"#s18"<:AbstractString, AbstractVector{var"#s17"} where var"#s17"<:Symbol}, B}, df::AbstractDataFrame; view) in DataFrames at /home/j/.julia/packages/DataFrames/zXEKU/src/abstractdataframe/abstractdataframe.jl:1012
[22] filter(::Pair, df::AbstractDataFrame; view) in DataFrames at /home/j/.julia/packages/DataFrames/zXEKU/src/abstractdataframe/abstractdataframe.jl:1001
[23] filter(f, df::AbstractDataFrame; view) in DataFrames at /home/j/.julia/packages/DataFrames/zXEKU/src/abstractdataframe/abstractdataframe.jl:996