Compile-time constants (roadmap #22a)
fn squares(n):
var out = []
for i in range(n):
out = push(out, i * i)
out
const LIMIT = 10
const SQUARES = squares(LIMIT) # computed once, while compiling
const NAMES = {"a": 1, "b": LIMIT * 2}
pub const PI: Float = 3.14159 # `pub` to use it from other modules
const NAME = exprat the top level; names are UPPER_CASE (so they never collide with locals or types). An optional type:const PI: Float = 3.14159.- The expression can call any function and use other constants. It's evaluated by the interpreter during compilation, and every use is replaced by the value written out as a literal (lists, maps, sets and constructors included), so lookup tables cost nothing at run time in any engine.
- A constant must be data (not a function), can't print, and can't reach the outside world (there is no
sysat compile time). An error while computing it (an index out of range, an overflow) is a compile error at its position.
Next steps for comptime: reflection on types (22b) and generating code (22c).