I am trying to update some of my code to make it work with Julia v0.7.0-beta2.0.
I am a bit confused about what is the right way to include a bunch of modules that refer to each other.
Assume I have three files that each contain a module:
1. Module: Types.jl
(a module that holds struct definitions)
module Types
export TwoNumbers
mutable struct TwoNumbers
a::Int64
b::Int64
end
end
2. Module: Operations.jl
(a module that contains certain functions that work on the custom structs defined in Module 1)
module Operations
using Types
export switchNumbers!
function switchNumbers!(tn::Types.TwoNumbers)
a = copy(tn.a)
b = copy(tn.b)
tn.a = b
tn.b = a
return nothing
end
end
3. Module MainModule.jl
( a parent module that uses the operations from module 2)
include("./Types.jl")
include("./Operations.jl")
module MainModule
using Operations, Types
export performOperation
function performOperation()
tn = TwoNumbers(1,2)
println("Original object: a=$(tn.a), b=$(tn.b)")
switchNumbers!(tn)
println("After switching: a=$(tn.a), b=$(tn.b)")
end
end
Output of the following commands in Julia 0.6.0:
include("MainModule.jl")
MainModule.performOperations()
>>>Original object: a=1, b=2
>>>After switching: a=2, b=1
However, with Julia v0.7.0-beta2.0, I get:
ERROR: LoadError: LoadError: ArgumentError: Package Types not found in current path:
- Run `Pkg.add("Types")` to install the Types package.
Stacktrace:
[1] require(::Module, ::Symbol) at ./loading.jl:816
[2] include at ./boot.jl:317 [inlined]
[3] include_relative(::Module, ::String) at ./loading.jl:1034
[4] include(::Module, ::String) at ./sysimg.jl:29
[5] include(::String) at ./client.jl:393
[6] top-level scope at none:0
[7] include at ./boot.jl:317 [inlined]
[8] include_relative(::Module, ::String) at ./loading.jl:1034
[9] include(::Module, ::String) at ./sysimg.jl:29
[10] include(::String) at ./client.jl:393
[11] top-level scope at none:0
in expression starting at /<PATH>/TestModules/Operations.jl:2
in expression starting at /<PATH>/TestModules/MainModule.jl:2
My question is: What is the best practice to include several files with modules and interdependencies into a parent module MainModule.jl (in Julia 0.7)?