Module imports
For information about creating a module, see Modules.
Modules can be imported using the import
keyword:
This program can use any public definitions from the os
module, such
as the input
function. See the standard library
documentation for a list of common modules and their public symbols.
By default, you have to specify the module prefix every time you call an external function. This may seem verbose at first, but it makes code much more readable and easier to understand - it's always clear which function from which module is being called. This is especially useful in large code bases.
Cyclic module imports are not allowed, like in Go.
Selective imports
You can also import specific functions and types from modules directly:
[!NOTE] This will import the module as well. Also, this is not allowed for constants - they must always be prefixed.
You can import several specific symbols at once:
Module import aliasing
Any imported module name can be aliased using the as
keyword:
[!NOTE] This example will not compile unless you have created
mymod/sha256/somename.v
(submodule names are determined by their path, not by the names of the .v file(s) in them).
You cannot alias an imported function or type. However, you can redeclare a type.