Modules and Imports
Zap supports imports from local files and from the standard library.
Import a module
Section titled “Import a module”import "math";Then use its exported names through the module name:
var value: math.Score = 10;Import selected symbols
Section titled “Import selected symbols”import "std/io" { println, printInt };Import a std module namespace
Section titled “Import a std module namespace”import "std/io" as io;
fun main() Int { io.println("hello"); return 0;}Import with an alias
Section titled “Import with an alias”import "helper.zp" { answer as value };import "std/io" as io;Public exports
Section titled “Public exports”Names are exported with pub:
pub fun answer() Int { return 0;}Folder imports
Section titled “Folder imports”Importing a directory loads .zp files from that directory, which is how the tests use grouped modules:
import "mods";Example layout
Section titled “Example layout”One common pattern is:
app.zpmath.zpapp.zp:
import "math";
fun main() Int { return math.lengthSquared(math.Vec2{ x: 3, y: 4 });}Standard library paths
Section titled “Standard library paths”Standard library modules live under std/..., for example:
std/iostd/stringstd/processstd/fsstd/pathstd/mathstd/errorstd/convertstd/mem