I have a module that contains precisely one exported function. Is it possible to give the module and the function the same name and use them with the syntax below?
e.g. for the module:
module myfunc
export myfunc
function myfunc(args)
return mystuff
end
end
I want to import and use with something like:
using myfunc
mystuff = myfunc(args)
Is there a way to do this (or similar), or do I just need to come up with a different name for the module than the function?
It is a (quite strong) convention in Julia to write modules in CamelCase, so it would be called MyFunc. Is there a reason it is getting wrapped in a module?
Thanks! The module wrapping is mostly because my impression is that this is the way to deploy the code for other people to use? There are also some non-exported functions within the module that are used by the main function.
julia> module a
_a() = println("Hello there!")
function Base.getproperty(m::Module, x::Symbol)
if m === a && x === :a
return getfield(m, :_a)
else
return getfield(m, x)
end
end
end
Main.a
julia> a.a()
Hello there!
The original desire to use only one name came because it’s a port of something from a different language, and I wanted to keep the API as consistent as possible. But in the end I’ve just come up with an acceptable alternative name for the container module.