Skip to content

std/prelude

std/prelude re-exports the most commonly used functions from the standard library. These symbols are available in every Zap program without any import statement.

The following functions work without any import:

// From std/io
println(s: String) Void
printInt(i: Int) Void
printFloat(f: Float) Void
printBool(b: Bool) Void
printChar(c: Char) Void
eprintln(s: String) Void
getLn() String

That’s why simple programs like this work without any imports:

fun main() Int {
println("Hello, Zap!");
printInt(42);
return 0;
}

You can also import std/prelude to get additional re-exported symbols:

import "std/prelude" { println, printInt, cwd, join, toString };
fun main() Int {
println(cwd());
println(join("/tmp", "output.txt"));
println(toString(42));
printInt(42);
return 0;
}

std/prelude pulls in APIs from:

Source moduleWhat’s re-exported
std/ioprintln, printInt, printFloat, printBool, printChar, eprintln, getLn
std/processcwd, exit, argc, argv
std/pathjoin, basename, parent
std/stringlen, fromChar, pushChar, eq
std/converttoString, toInt, toFloat, toBool, toChar
std/errorError, ErrorKind, Err, Kind
std/mathabs, min, max, sqrt, floor, ceil
import "std/prelude" { println, printInt, toString, abs };
fun main() Int {
var n: Int = -42;
println("Absolute value of " ~ toString(n) ~ " is " ~ toString(abs(n)));
printInt(abs(n)); // 42
return 0;
}