Workshop on Scheme

Answers to exercises: Thursday, July 20

The authors' answers to the exercises from Scheme and the art of programming are available only on MathLAN and only during the week of the workshop. Click here.


(define (ampex* ampex-1 ampex-2)
  (lambda (x)
    (* (ampex-1 x) (ampex-2 x))))


(define (sum func start stop)
  (let loop ((result 0)
             (index start))
    (if (<= stop index)
        result
        (loop (+ (func index) result) (+ index 1)))))

(define (trapezoid f a b . opt)
  (let* ((pieces (if (null? opt) 64 (car opt)))
         (base (/ (- b a) pieces)))
    (/ (* (- b a)
          (+ (f a)
             (sum (lambda (n) (* 2 (f (+ a (* base n))))) 1 pieces)
             (f b)))
       (* 2 pieces))))


(define (list-set! ls n obj)
  (if (zero? n)
      (set-car! ls obj)
      (list-set! (cdr ls) (- n 1) obj)))


This document is available on the World Wide Web as

http://www.math.grin.edu/~stone/events/scheme-workshop/Thursday-answers.html


created July 20, 1995
last revised July 20, 1995

John David Stone (stone@math.grin.edu)