Compile-time calculation: Difference between revisions
Content added Content deleted
(Lingo added) |
(Added Kotlin) |
||
Line 475: | Line 475: | ||
<lang julia>foo() = @fact 10</lang> |
<lang julia>foo() = @fact 10</lang> |
||
then the value of 10! = 3628800 is computed at parse-time and is inlined in the compiled function <code>foo</code>, as can be verified by inspecting the assembly code via the built-in function <code>code_native(foo, ())</code>. |
then the value of 10! = 3628800 is computed at parse-time and is inlined in the compiled function <code>foo</code>, as can be verified by inspecting the assembly code via the built-in function <code>code_native(foo, ())</code>. |
||
=={{header|Kotlin}}== |
|||
Compile time calculations are possible in Kotlin using the 'const' modifier provided one sticks to literals or other constants when specifying the calculation to be performed: |
|||
<lang scala>// version 1.0.6 |
|||
const val TEN_FACTORIAL = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 |
|||
fun main(args: Array<String>) { |
|||
println("10! = $TEN_FACTORIAL") |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
10! = 3628800 |
|||
</pre> |
|||
=={{header|Lingo}}== |
=={{header|Lingo}}== |