aboutsummaryrefslogtreecommitdiff
path: root/buzzard/demo5.th
blob: d16ca1e0060b566cca1882f41a94f857aa844634 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
( recursive factorial.  given x on top, followed by )
( an "accumulator" containing the product except for x! )

: fact-help2

  dup if
    swap over swap
    *
    swap 1 -
    fact-help2
  then
;

: fact

  1 swap
  fact-help2
  drop
;

: demo5

  " The factorial of 3 is: " 3 fact . cr
  " The factorial of 5 is: " 5 fact . cr
;

demo5