Modules
ilusm uses use to import modules. No package manager, no install step - stdlib modules are always available, and your own files load with a path.
Loading a stdlib module
use name loads a standard library module and makes its functions available as name.fn().
use fs
use jsn
use net
use trl
data = jsn.dec(fs.rd("data.json"))
res = net.get("https://api.example.com/")
There are 345 stdlib modules. Browse the full list in the stdlib catalog.
Builtins - no use needed
These are always available without any import:
| Builtin | What it does |
|---|---|
prn(x) | Print any value |
len(x) | Length of a list or string |
str(x) | Convert to string |
int(x) | Convert to integer |
typ(x) | Get type name as string |
try(f) | Call f, catch errors |
err(msg) | Raise an error |
asr(cond) | Assert - raise if falsy |
Loading your own files
use "path.ilu" loads a file relative to the importing file's directory. The file runs in a fresh environment and all its top-level bindings are copied into the caller.
# mylib.ilu
greet(name) =
$"hello {name}"
# main.ilu (same directory)
use "mylib.ilu"
prn greet("ibot") # "hello ibot"
Paths are relative to the file doing the importing:
use "utils/helpers.ilu"
use "../shared/config.ilu"
Duplicate use is ignored
Loading the same module or file twice has no effect - the second use is silently ignored.
use jsn
use jsn # ignored, no error
Where to put use
use statements go at the top of your file, before any other code. This is a convention but also helps readability - it's immediately clear what a file depends on.
use fs
use jsn
use trl
# rest of your program
data = jsn.dec(fs.rd("input.json"))
names = trl.map(data.users, \(u) u.name)