(define factorial ; 1 x 2 x ... x n
(lambda (n)
(if (= n 1)
1
(* (factorial (- n 1)) n))))
(define sum-of-first ; 1 + 2 + ... + n
(lambda (n)
(if (= n 1)
1
(+ (sum-of-first (- n 1)) n))))
Note that each computes a series. The only thing that differs is the
function used on the series terms (* or +)
Write make-series to take f as an argument and produce the
appropriate procedure. Here is the form:
(define make-series
(lambda (f)
;; Return a procedure that computes
;; the correct series for f
))
Then factorial and sum-of-first can be defined like this:
(define factorial (make-series *))
(define sum-of-first (make-series +))