RECURSE
RECURSE ( ---)
Append the execution semantics of the current definition to the current definition.
The usual example is the coding of the factorial function:
: FACTORIAL ( +n1 -- +n2) DUP 2 < IF DROP 1 EXIT THEN DUP 1- RECURSE * ;
Specific Flash Forth
n2 = n1(n1-1)(n1-2)...(2)(1), the product of n1 with all positive integers less than itself (as a special case, zero factorial equals one). While beloved of computer scientists, recursion makes unusually heavy use of both stacks and should therefore be used with caution.
: test01 ( n ---) dup 1- dup 0 > if test01 then . ;