Exercise 2.36: The procedure accumulate-n
is similar to accumulate except that it takes as its third argument a
sequence of sequences, which are all assumed to have the same number of
elements. It applies the designated accumulation procedure to combine all the
first elements of the sequences, all the second elements of the sequences, and
so on, and returns a sequence of the results. For instance, if s is a
sequence containing four sequences, ((1 2 3) (4 5 6) (7 8 9) (10 11
12)), then the value of (accumulate-n + 0 s) should be the sequence
(22 26 30). Fill in the missing expressions in the following definition
of accumulate-n:
(define (accumulate-n op init seqs)
(if (null? (car seqs))
nil
(cons (accumulate op init ⟨??⟩)
(accumulate-n op init ⟨??⟩))))
练习 2.36:过程 accumulate-n 与 accumulate 类似,不同之处在于它的第三个参数是一个序列的序列,且假定所有序列的元素个数相同。它将指定的累积过程应用于所有序列的第一个元素、所有序列的第二个元素,以此类推,并返回结果的序列。例如,若 s 是一个包含四个序列的序列,((1 2 3) (4 5 6) (7 8 9) (10 11 12)),则 (accumulate-n + 0 s) 的值应为序列 (22 26 30)。填写下列 accumulate-n 定义中缺失的表达式:
(define (accumulate-n op init seqs)
(if (null? (car seqs))
nil
(cons (accumulate op init ⟨??⟩)
(accumulate-n op init ⟨??⟩))))
(define (accumulate-n op init seqs)
(if (null? (car seqs))
nil
(cons (accumulate op init ⟨??⟩)
(accumulate-n op init ⟨??⟩))))