diff --git a/ueforth/common/base_tests.fs b/ueforth/common/base_tests.fs index 6a45ed0..f042fc1 100644 --- a/ueforth/common/base_tests.fs +++ b/ueforth/common/base_tests.fs @@ -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 diff --git a/ueforth/common/boot.fs b/ueforth/common/boot.fs index 8adf584..9eb9744 100644 --- a/ueforth/common/boot.fs +++ b/ueforth/common/boot.fs @@ -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 ;