Compile-time calculation: Difference between revisions
Content added Content deleted
Line 499: | Line 499: | ||
You can also calculate all factorials for 1 to 20 before defining fact method : |
You can also calculate all factorials for 1 to 20 before defining fact method : |
||
<lang Oforth>20 seq map(#[ seq reduce(#*) ]) Constant new: ALLFACTS |
<lang Oforth>20 seq map(#[ seq reduce(#*) ]) Constant new: ALLFACTS |
||
func: fact(n) { n ifZero: [ 1 ] else: [ ALLFACTS at(n) ] } |
func: fact(n) { n ifZero: [ 1 ] else: [ ALLFACTS at(n) ] } |
||
ALLFACTS println</lang> |
|||
{{out}} |
|||
<pre> |
|||
[1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 871 |
|||
78291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000, 12164510040883 |
|||
2000, 2432902008176640000] |
|||
</pre> |
|||
=={{header|OxygenBasic}}== |
=={{header|OxygenBasic}}== |