Notes: The exercise 2.37 on Hexlet's site has an error, noted in the comments. Also, their page for exercise 2.38 should probably have 0 tests. And finally, I did not calculate the exact number in the final exercise 2.43, but I included a relevant discussion.
13 lines
359 B
Scheme
13 lines
359 B
Scheme
#lang sicp
|
|
|
|
(define (accumulate op initial sequence)
|
|
(if (null? sequence)
|
|
initial
|
|
(op (car sequence)
|
|
(accumulate op initial (cdr sequence)))))
|
|
|
|
(define (horner-eval x coefficient-sequence)
|
|
(accumulate (lambda (this-coeff higher-terms)
|
|
(+ (* higher-terms x) this-coeff))
|
|
0
|
|
coefficient-sequence))
|