;; File trfac.scm ;; Author: Robert Keller ;; Purpose: tail-recursive factorial using McCarthy's transformation (load "tester.scm") (define (fac n) (a 1 1 n)) (define (a i f n) (if (<= i n) (b i f n) (c i f n))) (define (b i f n) (a (+ i 1) (* f i) n)) (define (c i f n) f) (test (fac 4) 24) (test (fac 5) 120) (test (fac 10) 3628800)