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:
(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.
(evens '(a b c d e f g))
which would/should return:
(b d f)
and:
(evens (LIST 's 't 'u 'v 'w 'x 'y 'z))
which would/should return:
(t v x z)
and:
(evens '(f (a b) c (d e d) (b a) f) )
which would return:
((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. Thanks in advance
Okay, I think that i have come up with a recursive function to my example that i have been trying to work out:
(define mylist '(1 2 3 4 5 6 7))
(define (evens lst)
(define (do-evens lst odd)
(if (null? lst)
lst
(if odd
(do-evens (cdr lst) #f)
(cons (car lst) (do-evens (cdr lst) #t)))))
(do-evens lst #t))
any thoughts?