EDITTED: SOLVED can someone delete/lock posted I am sorry......
I was given a Scheme homework. This is my first time programming in Scheme. I program in C++. So I have some programming knowledge. I am not asking any of you to do it or an answer for it. I just need help understanding why my code is acting up.
I am using the program Dr. Scheme.
This is the assignment:
Define a procedure (rac) which returns the LAST element of a list (RAC is CAR spelled backwards)
Example: (RAC (LIST 'A 'B 'C)) -> C
The above code just to get a understanding of how to get element is the list. I know cdr removes the first element of the list and returns the rest of the list. Also the above code if I try to test for the empty list only it doesn't return the empty list back eitherCode:(define rac (lambda ls (COND ((null? ls) ls) (ELSE (cons (rac (cdr ls)) () )))))
I do know that (cons '(a) () ) will result with ((a)) a list within a list.
but it I try something simple like:
I enter (rac '(a b)) I get back the empty List ().Code:(define rac (lambda ls (cdr ls)))
If I Try (rac '(a b c d)) I get the empty list again.
I don't understand why. Can someone help me and point me in the right direction.
XI Wiki

