Adding RECURSE.

This commit is contained in:
Brad Nelson
2021-06-26 12:07:38 -07:00
parent 72918d5d24
commit 9b75bb27cf
2 changed files with 7 additions and 0 deletions

View File

@ -80,3 +80,7 @@ e: test-comments-compiled
foo 999 = assert 789 = assert 456 = assert 123 = assert
;e
e: test-recurse
: factorial dup 0= if drop 1 else dup 1- recurse * then ;
5 factorial 120 = assert
;e

View File

@ -82,6 +82,9 @@
: repeat ['] branch , , here swap ! ; immediate
: aft drop ['] branch , here 0 , here swap ; immediate
( Recursion )
: recurse current @ @ aliteral ['] execute , ; immediate
( Compound words requiring conditionals )
: min 2dup < if drop else nip then ;
: max 2dup < if nip else drop then ;