1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; Standard Library Procedures and Macros ;;
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10 ; Join two lists together
14 (cons (car l1) (join (cdr l1) l2))))
16 ; Append an arbitrary number of lists together
17 (define (append . lists)
20 (if (null? (cdr lists))
22 (join (car lists) (apply append (cdr lists))))))
24 ; Reverse the contents of a list
28 (append (reverse (cdr l)) (list (car l)))))
32 (define-macro (while condition . body)
36 (begin ,@body (loop))))
41 (define-macro (backwards . body)
42 (cons 'begin (reverse body)))
44 (define method '(while (> counter 0)
45 (display counter) (newline)
46 (set! counter (- counter 1))))
51 (display counter) (newline)
52 (set! counter (- counter 1))))
54 ; Basic iterative summation. Run this on large numbers to
55 ; test garbage collection and tail-call optimization.
58 (define (sum-iter total count maxcount)
59 (if (> count maxcount)
61 (sum-iter (+ total count) (+ count 1) maxcount)))
65 ; Recursive summation. Use this to compare with tail call
66 ; optimized iterative algorithm.
67 (define (sum-recurse n)
70 (+ n (sum-recurse (- n 1)))))