<< Previous exercise (2.35) | Index | Next exercise (2.37) >>

But (lambda (s) (car s)) does not return car (the procedure) but the car of a pair. The notation (lambda (s) (car s)) shows the used operation in the mapping process more explicit.

(define (accumulate-n op init seqs) (if (null? (car seqs)) nil (cons (accumulate op init (map (lambda (s) (car s)) seqs)) (accumulate-n op init (map (lambda (s) (cdr s)) seqs))))) ;Maybe a helpful stepping stone. ;Example in Mit-Scheme: ;(user) => (map (lambda (s) (cdr s)) '((1 2 3) (4 5 6))) ;Value: ((2 3) (5 6))

Accumulate-n.

Given a sequence of sequences, applies accumulate to the first item from each, then the next item of each, etc.

Subproblem: define a proc that returns the first item from each nested sequence, and another that returns the remaining parts (accumulate-n will accumulate the former, and call itself with the latter):

Originally I had (map (lambda (s) (car s)) sequence), but (lambda (s) (car s)) is just a function that returns car ...