KAL modules & IMPORT
Sharing code between scripts with IMPORT: what modules may contain, how resolution works and every M-error.
IMPORT pulls constants and functions out of a named module so several scripts can share one implementation.
Syntax#
IMPORT { symbol1, symbol2 } FROM "module_name";
- Exactly one line, at the top of the file, before the
AUTOMATIONblock. - Up to 32 imports per script.
- Module names are letters, digits,
-and_.
What a module contains#
A module is KAL source whose AUTOMATION block holds only CONSTANT and FUNCTION declarations β no triggers, no actions at module level, no nested imports:
// inside module "pricing_lib"
AUTOMATION pricing_lib {
CONSTANT TAX_RATE = 1.08;
FUNCTION with_tax(amount AS NUMBER) AS NUMBER {
RETURN amount * TAX_RATE;
}
}
Using an import#
KAL VERSION 2.0;
IMPORT { with_tax, TAX_RATE } FROM "pricing_lib";
AUTOMATION checkout {
WHEN COMMAND total (price AS NUMBER) {
REPLY "With tax: " + ("" + with_tax(price));
}
}
(This example is shown as a fragment because modules must exist in your server's module registry for the import to resolve β an unregistered module is a compile error, not a runtime surprise.)
How resolution works#
- Modules are registered per server. An import resolves against your server's module library only β there is no global library, no file system and no URL fetching.
- Missing module β
M001_MODULE_NOT_FOUND. Missing symbol βM003_EXPORT_NOT_FOUND. - There is currently no dashboard page for uploading modules; the library is managed by the platform. Marketplace packages that need shared code declare it in their package rather than reaching into other servers' registries.
Limits#
| Rule | Value |
|---|---|
| Imports per script | 32 |
| Modules per server | 256 |
| Module source size | 200,000 bytes |
| Transitive imports | Not allowed (a module cannot import) |
The M-error family#
| Code | Meaning |
|---|---|
M001_MODULE_NOT_FOUND | No such module in this server's registry |
M002_CIRCULAR_MODULE_DEPENDENCY | Import cycle (defensive; imports cannot nest) |
M003_EXPORT_NOT_FOUND | The module does not export that symbol |
M004_DUPLICATE_IMPORT | Same symbol imported twice |
M005_INVALID_EXPORT | Export is not a CONSTANT or FUNCTION |
M006_INVALID_MODULE_IDENTIFIER | Bad module name |
M007_GUILD_REQUIRED | Compiled without a server context (tooling) |
M008_MODULE_SYNTAX_ERROR | The module source itself does not compile |
M009_MODULE_IMPORTS_UNSUPPORTED | A module tried to import |
M010_MALFORMED_IMPORT | The IMPORT line is malformed |
M011_IMPORT_LIMIT_EXCEEDED | More than 32 imports |