Evaluate a function at compile time

An ordinary function can compute a constant. moon evaluates the call while building the program when every argument is a compile-time constant.

No marker is needed, but the body must be pure and bounded. moon reports a check error at the constant when the function performs I/O, creates a shared object or does not terminate.

fn square(value: int) -> int { value * value }

let SIDE = square(12)

fn main() {
  println(SIDE)
}
Output & diagnostics
Expected:
144
Ctrl/⌘+Enter runs the current lesson.