Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Is there a way overload a function, `fn`, in a `Module Module1` so that it can only be called using `Module1.fn`?

$
0
0

@xiaodai wrote:

I am defining size in my module JDF, but I only want it to ever be called using JDF.size. Can I do that?

module JDF

using Base:size

JDF.size(df, val) = JDF.size(df, Val(val))

JDF.size(df, ::Val{1}) = 1
JDF.size(df, ::Val{2}) = 2
end

Now

@which size("abc", 1)

shows the location in my JDF, even though I didn’t export it.

Is there a way to do it so that JDF.size needs to be called and size ignores the function defined in the module JDF?

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 2795

Latest Images

Trending Articles



Latest Images