Hi everybody!
I have a hard time to understand how method extension really works and I hope you can help me with that. Let’s look at a concrete example and talk about the DataStructures module with SortedSet
.
So DataStructures.jl contains
import Base: show
and sorted_set.jl defines a method by
function Base.show(io::IO, m::SortedSet{K,Ord}) where {K,Ord <: Ordering}
which means that even though show
is not exported in the DataStructure package, it can be called by show(mysortedset)
from outside the module after loading the package with using DataStructures
. What I don’t really understand here is why sorted_set.jl defines this method with Base.show
instead of just show
, which is what I would expect according to section 25.1 of the manual.
For example DataStructures.jl also contains
import Base: push!
ans sorted_set.jl defines a method by
@inline function push!(m::SortedSet, k_)
and this method can also be called outside the module by push!(mysortedset, somestuff)
even tough it is not exported either. So where is the difference in this two cases? Or are they actually aquivalent? Or does this have to do with the @inline
?
Even more trouble causes the method setdiff!
for me. There is NO line like
import Base: setdiff!
(just import Base: setdiff
, which I suppose to be a different name), but the method
function setdiff!(m1::SortedSet, iterable)
defined in sorted_set.jl can be called the same way as push!
. That’s what I complete don’t understand since the method is not exported neither imported for method extension. From my understaind it should not be possible to call it with just settdiff!(mysortedset, somestuff)
, but I can confirm it is. My expectation would be, again referring to section 25.1 of the manual, that it must be called by DataStructures.settdiff!(mysortedset, somestuff)
.
I would really highly appreciate if someone was able to explain me what is going on here and tell me the point that I have missed so far. Thanks a lot!