I’m having a bit of trouble implementing this program in Scheme, although I think I’m 90% of the way there. Unfortunately I need to be a little vague about it since this is a homework assignment.
I want to (A B C D ) to return ( B D) . but i am getting an error that says The object (), passed as an argument to safe-car, is not a pair
| ”
This is my code:
(DEFINE (other_el lis)
(COND
(( NULL? lis ) '())
((LIST? lis)
(append (CADR lis) (other_el (CDR lis))))
(ELSE (show " USAGE: (other_el [LIST])"))))
There are a number of minor issues with this code that should be mentioned before I demonstrate the proper code.
Anyway, here is the function you are looking for:
I tested the function in DrRacket 5.3 and (evens ‘(A B C D)) returns ‘(B D), as you specified. If you have any trouble, let me know. Good luck with your homework!