Skip to content

Modules and Imports

Zap supports imports from local files and from the standard library.

import "math";

Then use its exported names through the module name:

var value: math.Score = 10;
import "std/io" { println, printInt };
import "std/io" as io;
fun main() Int {
io.println("hello");
return 0;
}
import "helper.zp" { answer as value };
import "std/io" as io;

Names are exported with pub:

pub fun answer() Int {
return 0;
}

Importing a directory loads .zp files from that directory, which is how the tests use grouped modules:

import "mods";

One common pattern is:

app.zp
math.zp

app.zp:

import "math";
fun main() Int {
return math.lengthSquared(math.Vec2{ x: 3, y: 4 });
}

Standard library modules live under std/..., for example:

  • std/io
  • std/string
  • std/process
  • std/fs
  • std/path
  • std/math
  • std/error
  • std/convert
  • std/mem