10. comptime and const

comptime { ... } is executed at compile time by the interpreter and its result is burned into the constant pool — there are no macros. A top-level const is named in upper case, and its initializer is implicitly comptime:

fn fib(n: Int) -> Int =
  if n < 2 { n } else { fib(n - 1) + fib(n - 2) }

const FIB10: Int = comptime { fib(10) }

pub fn main() -> Unit !io =
  println(to_string(FIB10))
Open in playground
55