Although this question has been asked before, it appears that much has changed with respect to modules in Julia V1.0.
I'm trying to write a custom module and do some testing on it. From the Julia documentation on Pkg, using the dev
command, there is a way to create a git tree and start working.
However, this seems like overkill at this point. I would like to just do a small local file, say mymodule.jl
that would be like:
module MyModule
export f, mystruct
function f()
end
struct mystruct
x::Integer
end
end # MyModule
It appears that it used to be possible to load it with
include("module.jl")
using MyModule
entering the include("module.jl")
, it appears that the code loads, i.e. there is no error, however, using MyModule
gives the error:
ArgumentError: Package MyModule not found in current path:
- Run `import Pkg; Pkg.add("MyModule")` to install the MyModule package.
I notice that upon using include("module.jl")
, there is access to the exported function and struct using the full path, MyModule.f()
but I would like the shorter version, just f()
.
My question then is: to develop a module, do I need to use the Pkg dev
command or is there a lighter weight way to do this?
In order to use a local module, you must prefix the module name with a .
.
using .MyModule
When using MyModule
is run (without the .
), Julia attempts to find a module called MyModule
installed to the current Pkg environment, hence the error.
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