I have to write a scheme function which does the following:
Define a SCHEME function, named (rev p)
, which takes a pair as an argument and evaluates to
another pair with the first and second elements in the pair p in reverse order. For instance,
( rev ( cons 1 2))
> (2 . 1)
Here is my code:
(define (rev p)
(cond ((null? p) '())
(not (pair? (car p)) p)
(else (append (rev (cdr p)) (list (rev (car p))))
However, my code returns (1 . 2)
when I test it when it should be returning (2 . 1)
.