Compile-time calculation: Difference between revisions
Content added Content deleted
(Added EchoLisp) |
|||
Line 563: | Line 563: | ||
<lang Oforth>10 seq reduce(#*) Constant new: FACT10 |
<lang Oforth>10 seq reduce(#*) Constant new: FACT10 |
||
: newFunction FACT10 . ;</lang> |
|||
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 |
||
: fact(n) n ifZero: [ 1 ] else: [ ALLFACTS at(n) ] ; |
|||
ALLFACTS println</lang> |
ALLFACTS println</lang> |