with v0.4.0
Execute a function at comptime
#can be used both during comptime and runtime
fn squared(n:Int)->Pointer[Int]:
var tmp = Pointer[Int].alloc(n)
for i in range(n):
tmp.store(i,i*i)
return tmp
def main():
#alias: during comptime
alias n_numbers = 5
alias precaculated = squared(n_numbers)
for i in range(n_numbers):
print(precaculated.load(i))
precaculated.free()
Returns a pointer with pre-calculated values during compilation and using it at runtime.
By not using alias.
# using var instead of alias
var precaculated = squared(n_numbers)