I need to return from a list only those values which are odd so I am trying to break my list using car and cdr functions. I have a recursive funciton call that checks if the Car returns a list then further break it using car and cdr , otherwise just pass the first element to a function call check if Odd.
The problem with the special case (10 11 (12 13)) is that car returns 10 cdr returns (11 (12 13))
then in second iteration car returns (11 (12 13)) cdr returns (11 (12 13))
so How can i further break my list using car and cdr. I need to preserve the brackets in my final answer as well as only return the list having odd values of integers.
car
of(11 (12 13))
is11
. It looks like you have some kind of logic error in your program, because at a high level the approach you describe sounds like it would work, as long as you are careful to recurse when you encounter a list such as with((12 13))
. – Justin Ethier