CS2322

Laboratory Problem 16

Reduction

In this problem we wish to develop a reduction operator (here we use the term operator in the technical sense that an operator is a function, defined on some class of functions, which produces a result which is also a function. reduce should have the form:

(define reduce

(lambda (fn)

...))

where fn is a function of one argument. reduce should produce a result function, having one argument, ls, which when applied to ls, will reduce that argument list to a single value by successive applications of fn to the elements of ls . For example:

((reduce +) '(1 3 5 7 9)) ==> 25

This is accomplished in steps in the order:

(+ 1 3) ==> 4

(+ 4 5) ==> 9

(+ 9 7) ==> 16

(+ 16 9) ==> 25

Similarly:

((reduce max) '(2 -4 6 8 3 1)) ==> 8

((reduce (lambda (x y) (and x y))) '(#t #t #t)) ==> #t

(define plus-reduce (reduce +))

(plus-reduce '(3 5 7 9)) ==> 24

Lab 16 Scheme Code