read
(define (accumulate op initial sequence)
(if (null? sequence)
initial
(op (car sequence)
(accumulate op initial (cdr sequence)))))
(define (fold-left op initial sequence)
(define (iter result rest)
(if (null? rest)
result
(iter (op result (car rest))
(cdr rest))))
(iter initial sequence))
> (reverse (list 1 2 3 4 5))
(5 4 3 2 1)
> (reverse_ (list 1 2 3 4 5))
(5 4 3 2 1)
> (reverse_2 (list 1 2 3 4 5))
(5 4 3 2 1)
>
(if (null? sequence)
initial
(op (car sequence)
(accumulate op initial (cdr sequence)))))
(define fold
-right accumulate)(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 nil (list))
(define (reverse_ sequence)
(fold
(define (reverse_2 sequence)
(fold
(define solution (lambda (x y) (append y (list x))))
(define solution2 (lambda (x y) (cons y x)))
> (reverse (list 1 2 3 4 5))
(5 4 3 2 1)
> (reverse_ (list 1 2 3 4 5))
(5 4 3 2 1)
> (reverse_2 (list 1 2 3 4 5))
(5 4 3 2 1)
>