;;; add-pairs: add the elements of a given list, two by two, and ;;; construct a list of the results ;;; John David Stone ;;; Department of Mathematics and Computer Science ;;; Grinnell College ;;; stone@cs.grinnell.edu ;;; created February 2, 2000 ;;; last revised February 2, 2000 ;;; Given: ;;; LS, a list of numbers. ;;; Result: ;;; SUMS, a list of numbers. ;;; Precondition: ;;; The length of LS is even. ;;; Postconditions: ;;; Let |LS| be the length of LS. ;;; (1) The length of SUMS is |LS| / 2. ;;; (2) For every natural number k less than |LS| / 2, the element ;;; at position k of SUMS is the sum of the elements at positions ;;; 2k and 2k + 1 of LS. (define add-pairs (lambda (ls) (if (null? ls) null (cons (+ (car ls) (car (cdr ls))) (add-pairs (cdr (cdr ls)))))))