Organizing sub-modules

There are generally two patterns for organizing sub-module files. Let's take a look at each:

  • The first one involves a simpler situation where each sub-module is fully contained in a single source file, as follows:
module MyPackage
include("sub_module1.jl")
include("sub_module2.jl")
include("sub_module3.jl")
end
  • The second one involves larger sub-modules where there could be several source files for each sub-module. In that case, the source code of a sub-module resides in a subdirectory:
# MyPackage.jl
module MyPackage
include("sub_module1/sub_module1.jl")
include("sub_module2/sub_module2.jl")
include("sub_module3.jl")
end
  • Of course, the sub module's directory may include multiple files. In the preceding example, sub_module1 may contain several more source files, which are shown in the following code snippet:
# sub_module1.jl
module SubModule1
include("file1.jl")
include("file2.jl")
include("file3.jl")
end

Next, we will look into how to reference symbols and functions between the modules and these sub-modules.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.86.138