Updated links in readme.
[scheme.forth.jl.git] / src / scheme-library-6-testing.scm
1 ;; TESTING
2
3 ; Test for the while macro.
4 (define (count)
5   (define counter 10)
6   (while (> counter 0)
7          (display counter) (newline)
8          (set! counter (- counter 1))))
9
10 ; Basic iterative summation.  Run this on large numbers to
11 ; test garbage collection and tail-call optimization.
12 (define (sum n)
13
14   (define (sum-iter total count maxcount)
15     (if (fix:> count maxcount)
16       total
17       (sum-iter (fix:+ total count) (fix:+ count 1) maxcount)))
18   
19   (sum-iter 0 1 n))
20
21 ; Recursive summation. Use this to compare with tail call
22 ; optimized iterative algorithm.
23 (define (sum-recurse n)
24   (if (fix:= n 0)
25     0
26     (fix:+ n (sum-recurse (fix:- n 1)))))
27