Compile-time calculation: Difference between revisions

m (removed omit from|Lua (and will implement))
Line 665:
put fac10()
-- 3628800</lang>
 
=={{header|Lua}}==
Lua's compiler will attempt to fold constant expressions, which appears to be enough to satisfy this specific task's requirements:
<lang lua>local factorial = 10*9*8*7*6*5*4*3*2*1
print(factorial)</lang>
{{out}}<pre>3628800</pre>
Proof via disassembly (Lua 5.3 used - the lookup of global "print" may vary a bit among 5.x versions, but not significant):
<pre>> luac -l compiletime.lua
 
main <compiletime.lua:0,0> (5 instructions at 0000000000ac8a40)
0+ params, 3 slots, 1 upvalue, 1 local, 2 constants, 0 functions
1 [1] LOADK 0 -1 ; 3628800
2 [2] GETTABUP 1 0 -2 ; _ENV "print"
3 [2] MOVE 2 0
4 [2] CALL 1 2 1
5 [2] RETURN 0 1
</pre>
 
=={{header|m4}}==
Anonymous user