Sage-Code Laboratory
index<--

Julia Modules

Julia is modular. A module is like a package that encapsulate several members. A module can import other modules and can export members. One module is stored in one or many files. One file can contain one or more modules. So the module is a supra-structure used to group together members. Each member exported or not.

Syntax:

module <module_name>
[import <module>]
...
[export <members>]
...
[declare_members]
...
end

import & export

A module can have two optional keywords: import and export. The module is using hoisting technique. We can export a member before we declare the member. So the export is above the declaration region. Julia has 3 standard modules that we do not have to import: Main, Core, and Base.

When you import a module all its exported members can be used in the global namespace of the current module. The private members of the imported modules can be used only with dot "." punctuation: ModuleName.member_name. Module name are usually starting with capital letters. Member name is usually lower-case except types that start with upper-case letter.


Read next: Exceptions