forthkit icon indicating copy to clipboard operation
forthkit copied to clipboard

recurse doesn't work, here is my fix

Open Eszartek opened this issue 7 years ago • 9 comments

Using the following factorial definition as a test:

: fac dup 1 = if drop 1 else dup 1- recurse  * then ;

"5 fac ." returns 20 as a result which is incorrect.

Redefining recurse (and fac again which depends on it) as :

: recurse last @ code> @ , ; immediate
: fac dup 1 = if drop 1 else dup 1- recurse  * then ;

"5 fac ." returns 120 as a result, which is correct.

Eszartek avatar Aug 23 '17 11:08 Eszartek