retroforth/example/RecursiveFactorial.forth

22 lines
284 B
Text
Raw Normal View History

# example|RecursiveFactorial
Declare module constant (prevents reloading when using `import`):
````
:example|RecursiveFactorial ;
````
----
````
:<factorial>
dup #1 -eq? 0; drop
dup n:dec <factorial> * ;
:factorial
dup n:zero?
[ n:inc ]
[ <factorial> ] choose ;
````