Pelago
Modules and imports

Import paths

How an import path is resolved: packages such as std, modules of your own package, relative paths with . and .., and folders as module groups.

PathMeaning
std.osThe first part is a package, here the standard library.
geometry.shapesThe first part names a top-level module of your own package.
.siblingA leading dot is relative to the current file's folder.
..util.strings.. goes up one folder.

A folder groups modules: shapes/circle.pel is shapes.circle, and deep/x/m.pel is deep.x.m. The imported module is bound under its last name: import shapes.circle gives circle.

deep/x/m.pel:

import ..helper

pub fn g() -> int = helper.h()

deep/helper.pel:

pub fn h() -> int = 7

shapes/circle.pel:

pub fn area(r: int) -> int = 3 * r * r

main.pel:

import deep.x.m
import .shapes.circle
import c = shapes.circle

fn main() {
    print(m.g(), circle.area(2), c.area(1))
}

pelago run . prints:

7 12 3

.shapes.circle starts from the importing file's folder; ..helper in deep/x/m.pel goes up to deep/ and finds helper.pel; import c = shapes.circle renames the binding.

Missing modules

main.pel:

import nothere

fn main() {}

pelago run . stops with:

main:1:8: error: there is no module or package `nothere`

On this page