Skip to content

Modules and Imports

All files in QangLang are modules. Modules are declared using the mod keyword and path to the module is provided with the import keyword.

mod lib = import("./lib.ql");

When a module is imported the first time, it is executed and cached.

lib.ql
println("Library imported!");
main.ql
mod lib = import("./lib.ql"); // "Library imported!"
fn main() {
mod lib = import("./lib.ql");
}
main(); // Nothing prints because the lib.ql has already executed.

Modules are also readonly, so a field on a module cannot be reassigned.

mod math = import("./math.ql");
math.sqrt = identity; // This is an error because math.sqrt cannot be reassigned.