Adding RECURSE.
This commit is contained in:
@ -80,3 +80,7 @@ e: test-comments-compiled
|
|||||||
foo 999 = assert 789 = assert 456 = assert 123 = assert
|
foo 999 = assert 789 = assert 456 = assert 123 = assert
|
||||||
;e
|
;e
|
||||||
|
|
||||||
|
e: test-recurse
|
||||||
|
: factorial dup 0= if drop 1 else dup 1- recurse * then ;
|
||||||
|
5 factorial 120 = assert
|
||||||
|
;e
|
||||||
|
|||||||
@ -82,6 +82,9 @@
|
|||||||
: repeat ['] branch , , here swap ! ; immediate
|
: repeat ['] branch , , here swap ! ; immediate
|
||||||
: aft drop ['] branch , here 0 , here swap ; immediate
|
: aft drop ['] branch , here 0 , here swap ; immediate
|
||||||
|
|
||||||
|
( Recursion )
|
||||||
|
: recurse current @ @ aliteral ['] execute , ; immediate
|
||||||
|
|
||||||
( Compound words requiring conditionals )
|
( Compound words requiring conditionals )
|
||||||
: min 2dup < if drop else nip then ;
|
: min 2dup < if drop else nip then ;
|
||||||
: max 2dup < if nip else drop then ;
|
: max 2dup < if nip else drop then ;
|
||||||
|
|||||||
Reference in New Issue
Block a user