const Functions and Compile-Time Evaluation
const func is a special type of function that can be evaluated at compile time. When all its parameters are compile-time constants, the function executes during the compilation phase, and the result is directly embedded in the program. This reduces runtime computation overhead.
Expressions in const function bodies must be const expressions and cannot include I/O operations, modifying global state, or other side effects. You can declare local variables with let (not var), and use control flow like if, match, and try.
Structs and classes can define const init constructors to support compile-time construction. The code on the right defines a Point struct with a const constructor, so instances can be created at compile time; distance is a const func that can calculate the distance between two points at compile time.
const functions don't always execute at compile time. When called in non-const contexts, they execute at runtime like normal functions.