Pelago
Modules and imports

Modules and imports

How files become modules: one page each on visibility with pub, import forms, import paths, re-exporting, the prelude and Islet packages.

Every .pel file is a module named after the file: geometry.pel is the module geometry. A folder of files groups modules, so shapes/circle.pel is shapes.circle. Run a folder to build all of its files together:

pelago run .

(pelago run main.pel on a single file sees only that file; give it the folder so sibling modules are found.)

TopicWhat it coversPage
pub, privWhat other modules may see: functions, constants, types, fields, methods.Visibility
import, useThe forms: whole module, renamed, some names, everything.Imports
.sibling, ..up, std.osHow a path finds a module.Import paths
pub importPassing names on to your own importers.Re-exporting
PreludeWhat is in scope without an import.The prelude
IsletDependencies by package name.Packages

Rules at a glance

  • Names are private to their module unless marked pub.
  • The order of declarations inside a module does not matter.
  • Modules may import each other; cycles are allowed.
  • A name declared in a module wins over one it imports.
  • Two imports that bring the same name are an error only when you use the name; write the module name in front to choose.

The standard library

core is built in and always available: lists, maps, strings, numbers, results and options, tasks. std holds modules you import when needed: std.io, std.fs, std.path, std.time, std.env, std.os, std.json, std.regex and std.big. See the library.

On this page