previous | index | next

Mutual Recursion

Q: The "odd part" of an empty list is what list?

A: The empty list

Q: How do we get the "odd part" of a nonempty list? (Hint: think of the "even part")

A: Cons the head onto the "even part" of the tail

     (define odd-part
       (lambda (lst)
         (if (null? lst)
             '()
             (cons (car lst) 
                   (even-part (cdr lst))))))

     (define even-part
       (lambda (lst)
         (if (null? lst)
             '()
             (odd-part (cdr lst)))))

previous | index | next