(define (fold-left op initial sequence) (define (iter result rest) (if (null? rest) result (iter (op result (car rest)) (cdr rest)))) (iter initial sequence)) (define (fold-right op initial sequence) (if (null? sequence) initial (op (car sequence) (fold-right op initial (cdr sequence))))) ; 1 ]=> (fold-right / 1 (list 1 2 3)) ; ; ;Value: 3/2 ; ; 1 ]=> (fold-left / 1 (list 1 2 3)) ; ; ;Value: 1/6 ; ; 1 ]=> (fold-right list '() (list 1 2 3)) ; ; ;Value: (1 (2 (3 ()))) ; ; 1 ]=> (fold-left list '() (list 1 2 3)) ; ; ;Value: (((() 1) 2) 3) ; 1 ]=> (fold-right + 0 (list 1 2 3 4)) ; ; ;Value: 10 ; ; 1 ]=> (fold-left + 0 (list 1 2 3 4)) ; ; ;Value: 10 ; fold-right and fold-left produce the same value for associative operators