Scheme Programming Help! | INFJ Forum

Scheme Programming Help!

Discussion in 'Computer Science' started by NewGuy2Scheme, Nov 10, 2012.

Share This Page

More threads by NewGuy2Scheme
  1. NewGuy2Scheme

    Joined:
    Nov 10, 2012
    Threads:
    1
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    MBTI:
    ISFP
    Enneagram:
    Two
    So i have been stuck trying to learn this Scheme language that i heard about from a friend of mines. What he said i should do is start small and work my way up to truly understanding it. So after reading a textbook that he had that discusses Scheme programming briefly, i am a little puzzled myself on how it works.

    So pretty much what i am trying to ask is that if i wanted to add a definition to a function called, let's say 'evens' from a couple of list i have define:

    (DEFINE list0 (LIST 'j 'k 'l 'm 'n 'o 'j) )
    (DEFINE list1 (LIST 'a 'b 'c 'd 'e 'f 'g) )
    (DEFINE list2 (LIST 's 't 'u 'v 'w 'x 'y 'z) )
    (DEFINE list3 (LIST 'j 'k 'l 'm 'l 'k 'j) )
    (DEFINE list4 (LIST 'n 'o 'p 'q 'q 'p 'o 'n) )
    (DEFINE list5 '((a b) c (d e d) c (a b) )
    (DEFINE list6 '((h i) (j k) l (m n)) )
    (DEFINE list7 (f (a b) c (d e d) (b a) f) )

    such that it does like the task below: evens

    which I have already created a adder function which i believe is to be:

    Code:
    (DEFINE (adder lis)
         (COND
            ((NULL? lis) 0)
            (ELSE (+ (CAR lis) (adder (CDR lis))))
    ))
    what might the definition for even be if i would want it to do like the task below:

    EVENS: (evens 1st) should return a new list, formed from the the even numbered elements taken 1st.

    Code:
    (evens '(a b c d e f g))
    which would/should return:
    Code:
    (b d f)
    and:

    Code:
    (evens (LIST 's 't 'u 'v 'w 'x 'y 'z))
    which would/should return:
    Code:
    (t v x z)
    and:

    Code:
    (evens '(f (a b) c (d e d) (b a) f) )
    which would return:
    Code:
    ((a b) (d e d) f)
    and both (evens '()) and (evens '(a))

    would return the empty list.

    I have been going through trail in error to practice but i am totally lost. I am really just curious as to what the recursive function code might look like. I get the concept (i think), For Example, (evens '(a b)) would return 'b' right. Thanks in advance
     
    #1 NewGuy2Scheme, Nov 10, 2012
    Last edited: Nov 10, 2012
Loading...

Share This Page