I’ve been working on the sicp and am trying to write the ‘last’ function using accumulate
(define (accumulate f x xs)
(if (null? xs)
x
(f (car xs)
(accumulate f x (cdr xs)))))
(last '(1 2 3 4 5)) ;;=> (5)
I tried this but it does not work
(define (last seq)
(accumulate (lambda (x y) x)
'()
seq))
Try this: