Results 1 to 2 of 2

Thread: Scheme nightmare     submit to reddit submit to twitter

  1. #1
    New Merits
    Join Date
    Nov 2005
    Posts
    233
    BG Level
    4

    Scheme nightmare

    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

    Code:
    (define rac (lambda ls 
                    (COND ((null? ls) ls)
                    (ELSE  (cons (rac (cdr ls)) () )))))
    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 either

    I do know that (cons '(a) () ) will result with ((a)) a list within a list.

    but it I try something simple like:

    Code:
    (define rac (lambda ls (cdr ls)))
    I enter (rac '(a b)) I get back the empty List ().

    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.

  2. #2
    New Merits
    Join Date
    Nov 2005
    Posts
    233
    BG Level
    4

    I figured it out. I didn't have an extra () in my code.

    Example (define rac (lambda (ls) (cdr ls)))

    That was making things werid.

    I am sorry for making this stupid post. ::slap:: Can someone delete or lock this thread up. Thanks.

Similar Threads

  1. Britain's Police to launch "dial-a-bobby" scheme
    By sunb1ind in forum General Discussion
    Replies: 2
    Last Post: 2008-02-10, 12:56
  2. Nightmare before christmas images for tattoo
    By arlania in forum General Discussion
    Replies: 10
    Last Post: 2008-01-02, 10:55
  3. Kitchen Nightmares
    By Correction in forum General Discussion
    Replies: 15
    Last Post: 2007-09-27, 17:33
  4. The stuff nightmares are made of.
    By Bartylby in forum General Discussion
    Replies: 45
    Last Post: 2007-03-18, 12:55
  5. Computer Naming Scheme
    By Justice in forum General Discussion
    Replies: 14
    Last Post: 2007-02-13, 16:59
  6. Nightmares
    By Warudo Ecksu in forum General Discussion
    Replies: 60
    Last Post: 2005-10-10, 08:29