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))
|