(define (accumulate op id term a next b)
(cond ((> a b) id)
(else (op (term a) (accumulate op id term (next a) next b)))))
; Write the function sum in terms of accumulate. sum adds terms related to the numbers from a to b.
(define (sum term a next b)
(accumulate ? ? ? ? ? ?))
> (sum factorial 1 (lambda (x) (+ x 1)) 3) ;; 1 + 2 + 6
9
; Write 1/factorial in terms of accumulate.
(define (1/factorial n)
(accumulate ? ? ? ? ? ?))
> (1/factorial 4)
1/24
; (CHALLENGE PROBLEM) Write the function range in terms of accumulate. range returns a list containing the numbers from 0 to n-1.
(define (range n)
(accumulate cons ? ? ? ? ?))
> (range 5)
'(0 1 2 3 4)
; (CHALLENGE PROBLEM) Using the Simply Scheme library (i.e., Choose Language... Simply Scheme), but using the SICP version of accumulate, above, write the function acronym that takes a list of words as its input and returns an acronym of those words.rs from a to b.
; pos is short for "position"
(define (acronym l)
(let ((boring-words '(the a an of in and or but)))
(accumulate word "" (lambda (pos) ?) 1 (lambda (x) (+ x 1)) ?)))
> (acronym '(the united states of america))
'usa