Pelago
Core types

core

The always-available library: primitive types, collections, text, options and results, tasks, and the interfaces everything else builds on.

core is the part of the library that needs no import. Every name it declares pub is in scope in every file, and the methods of its types come with the types, so xs.sort!(), name.toUpper() and n.checkedAdd(1) just work. It is written in Pelago itself, in compiler/core/core.pel and the modules under compiler/core/core/; the few functions marked ext are provided by the backend.

If you are new to this reference, read How to read this documentation first.

Modules

AreaWhat is in itPages
Primitive typesbool, char, every integer and float width, one page eachPrimitive types
Wide numbers (overviews)int128 to uint256, float16, float128, float256Wide integers, Wide and narrow floats
Textstring and str, chars, splitting, searching, parsingText: string, str, parsing
Collectionslist<T>, iter<T>, map<K, V>, set<T>Collections: list, iter, map, set
Absence and failureT? and T ! EOptions and results: option, result, error types
MathThe math namespaceMath

Not yet given their own pages (they exist in the source and are described inside the guide): braids (core/braid.pel), tasks and channels (core/tasks.pel), boxes, arenas and pools (core/boxes.pel, core/arena.pel, core/pool.pel), and the runtime support in core/rt.pel.

Interfaces

These interfaces are declared in core itself. Other types and the language use them. Each has its own page: Interfaces.

InterfaceMethodWhat it enables
showfn show(self) -> stringPrinting and #( ) interpolation.
eqfn eq(self, other: Self) -> bool== and !=. Plain struct and enum types have it already; an obj must say so.
order : eqfn cmp(self, other: Self) -> int<, >, <=, >=, sorting, min and max. A negative, zero or positive number.
hash : eqfn hash(self) -> intBeing a map key or a set member.
clonefn clone(self) -> Selfcopy on an obj. Plain data has it already.
converts<E>fn convert(self) -> ELets ? and to turn one error type into another. The name is a placeholder.
add, sub, mul, div, remfn add(self, other: Self) -> Self and so onThe operators +, -, *, /, % on your own types.
negfn neg(self) -> SelfUnary -.

Types declared in core

TypeMeaning
parse_errorA failed text-to-number conversion, with a message. It is show.
io_errorA failed file or stream operation: kind: io_kind and message.
io_kindnotFound, denied, invalid, other.

Functions in the prelude

FunctionSignatureBehaviour
printfn print(...values: any show)Writes the values to standard output with a line end.
assertfn assert(condition: bool)Stops the program when the condition is false.
panicfn panic(message: string) -> neverStops the program with the message.
todofn todo() -> neverMarks code not written yet; stops when reached.
unreachablefn unreachable() -> neverMarks a place that must not be reached; stops when reached.

Every stop prints stopped: <reason>, with the file and line when known, and ends the program with a non-zero status.

On this page