Chapter 2: Problem 38
The accumulate procedure is also known as fold-right, because it combines the first element of the sequence with the result of combining all the elements to the right. There is also a fold-left, which is similar to fold-right, except that it combines elements working in the opposite direction: (define (fold-left op initial sequence) (define (iter result rest) (if (null? rest) result (iter (op result (car rest)) (cdr rest)))) (iter initial sequence)) What are the values of (fold-right / 1 (list 123 )) (fold-left / 1 (list 123 )) (fold-right list nil (list 123 )) (fold-left list nil (list 123 )) Give a property that op should satisfy to guarantee that fold-right and foldleft will produce the same values for any sequence.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.