Skip to Content

Under construction

This page is still being written; content and examples may change.

Const Func

A const func is a function the compiler can evaluate at compile time: the compiler executes the function body during compilation and materializes the result as a constant. It has two faces — ordinary function and constant capability: at runtime it is called as usual, and in constant contexts the compiler interprets its body.

Compile-Time Evaluation

const func Fib(n: int) -> int { if n < 2 { return n; } return Fib(n - 1) + Fib(n - 2); } const Answer: int = Fib(10); const Greet: string = "con" + "stant"; func main() -> int { print(Answer, Greet); return 0; }
55 constant

Fib(10) is computed at compile time; Answer simply is 55. A const initializer can also reference earlier consts, and the compiler evaluates along the chain.

编写到此Written up to here

本页其余部分尚未完成,内容随时补充。The rest of this page is not written yet; more content will follow.

Last updated on October 11, 2026