go-first

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

demo5.th (339B)


      1 ( recursive factorial.  given x on top, followed by )
      2 ( an "accumulator" containing the product except for x! )
      3 
      4 : fact-help2
      5 
      6   dup if
      7     swap over swap
      8     *
      9     swap 1 -
     10     fact-help2
     11   then
     12 ;
     13 
     14 : fact
     15 
     16   1 swap
     17   fact-help2
     18   drop
     19 ;
     20 
     21 : demo5
     22 
     23   " The factorial of 3 is: " 3 fact . cr
     24   " The factorial of 5 is: " 5 fact . cr
     25 ;
     26 
     27 demo5