Skip to content

Print & Output

Print & Output

print and println are built-in functions - no import needed. Both take a single value.

Basic usage

func main() -> i32:
print("Hello, Thagore!")
println(42)
println(true)
return 0

print writes to stdout without a trailing newline. println appends a newline.

Formatting values

print and println accept str, bool, i32, i64, and f64 directly. std.string helpers still matter when you need to build composite strings:

import std.string as string
func main() -> i32:
let value: i32 = 7
let label = string.concat("answer = ", string.from_int(value))
println(label)
return 0

Stderr output

eprint and eprintln write to stderr:

func main() -> i32:
eprintln("error: something went wrong")
return 1

Flush

flush flushes buffered stdout output:

func main() -> i32:
print("loading...")
flush()
return 0

Using extern func printf

For C-style format-string output, declare printf via FFI:

extern func printf(fmt: str, value: i32) -> i32
func main() -> i32:
printf("The answer is %d\n", 42)
return 0