Modules
Jiang currently uses source files as modules. Imports connect source files, and imported APIs stay under a module namespace instead of being flattened into the current file.
File Imports
Section titled “File Imports”import "math.jiang";The default module name comes from the file name. After importing math.jiang, access public
declarations through math.Name:
Int value = math.add(1, 2);Import Aliases
Section titled “Import Aliases”Use an alias when the file name is not the module name you want:
import m = "utils/math.jiang";
Int value = m.add(1, 2);The alias names the target module namespace. It does not flatten imported declarations into the current module.
File Paths
Section titled “File Paths”A quoted import is a file path import:
import math = "utils/math.jiang";File paths are interpreted relative to the importing source file. Write the full path; imports do
not automatically add .jiang or search for a directory entry.
Quoted file imports are only for files inside the current package. To import another package, declare
it in package.ini and use an unquoted package import.
Visibility
Section titled “Visibility”Declarations that should be visible to other modules use public:
public struct Point { Int x; Int y;}
public Int distance(Point point) { return point.x + point.y;}Declarations without public are module-local.
Re-exports
Section titled “Re-exports”public import imports a module for local use and re-exports that module namespace as part of the
current module API:
public import leaf = "leaf.jiang";This does not flatten imported declarations:
import middle = "middle.jiang";
Int value = middle.leaf.answer();Use alias to give a type or an existing symbol another name:
alias Byte = UInt8;alias NameBytes = UInt8[];
alias add = math.add;If the right-hand side resolves to an existing namespace, type, value, or member symbol, the alias is bound in that same name domain. If it does not resolve to an existing symbol, the right-hand side is treated as type syntax and must be a valid type.
public alias re-exports a concrete public symbol through the current module API:
public alias answer = math.add;