I have multiple functions/dispatches for the same function name. I want to make sure they are all exported. Do I just need to include the name of the function in the export statement and let then Julia do the rest?
Example:
function hello(a::Int64, b::Int64)
#nothing
end
function hello(a::Bool, b::Bool)
#nothing
end
export hello
Will both of these be exported by just doing export hello
?
Yes, you export the function name, and that function has two method in this case, and both of them will be available.
And to add, there is no way to export a subset of the methods.
That's right. Actually, there is no version of the export
statement that would allow you to pick which method to export. You export the function.
Here is some code which illustrates the behavior:
julia> module FooBar
export foo
foo(x::Int) = 2
foo(x::Char) = 'A'
end
Main.FooBar
julia> foo
ERROR: UndefVarError: foo not defined
julia> @which foo
ERROR: "foo" is not defined in module Main
Stacktrace:
[1] error(::String) at .\error.jl:33
[2] which(::Module, ::Symbol) at .\reflection.jl:1160
[3] top-level scope at REPL[15]:1
julia> using .FooBar
julia> @which foo
Main.FooBar
julia> methods(foo)
# 2 methods for generic function "foo":
[1] foo(x::Char) in Main.FooBar at REPL[13]:4
[2] foo(x::Int64) in Main.FooBar at REPL[13]:3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With