How can you define a function to reverse a list in Scheme by using foldr and foldl?
foldr
foldl
What we want is a succinct solution to reverse a list i
Your rev1 'solution' doesn't compile... it would if you replaced list with l
rev1
list
l
> (define (rev1 l) (foldl cons l '())) > (rev1 '(1 2 3)) (3 2 1)
For your rev2 this works as the body:
rev2
> (foldr (lambda (a b) (append b (list a))) '(1 2 3) '()) (3 2 1)