Functions are the workhorses of Prism. They are cheap, typed, and composable — the same rules apply to a two-line helper and a full program.
Signatures
Every parameter carries its type. Return types are required except for main:
fn greet(name: str) -> str {
return "Hello, " + name + "!"
}
fn main() {
println(greet("Ada"))
}
Functions with no return value may omit the return type. Omission is preferred — it reads as “this does something, it doesn’t produce a value.”
All arguments are required
There are no default parameters or named arguments in v0.1.0. Pass every argument, in order:
fn serve(port: int, workers: int) {
println(port)
println(workers)
}
fn main() {
serve(8080, 8)
}
Collections
Build derived collections with a loop — closures and .map are not in v0.1.0:
fn main() {
let numbers = [1, 2, 3, 4]
let mut doubled: [int] = []
for n in numbers {
doubled = doubled + [n * 2]
}
}
Long-running work starts with spawn, which runs a function without blocking:
fn worker(label: str) {
println(label)
}
fn main() {
spawn worker("worker")
}
Failure handling
Builtins that can fail return a status code or a value you check explicitly — there is no
Result type or ? operator in v0.1.0:
async fn read_file(path: str) -> str {
return fs_read(path) // fs builtins return strings/ints directly
}
fn main() {
let contents = read_file("config.toml")
println(contents)
}
Note: the exact
fs_*builtin names are defined intests/test_fs_builtins.prism.
The pub keyword
Items are private to their module by default. pub exposes them:
pub fn visible_from_outside() {
println("hi")
}
This keeps module boundaries meaningful: the compiler enforces them, and the language server surfaces them as “private” in completions outside the module.