10-22-2013 Lab

posted Oct 22, 2013, 5:39 AM by Samuel Konstantinovich   [ updated Oct 24, 2013, 8:23 AM ]
Goal Recursion:

New Method: (list? x)  is true when x is a list, false otherwise.

(define MrE (lambda (L) 
              (cond 
                ( (null? L)       0 )
                ( (list? (car L)) (+ (MrE (car L))(MrE (cdr L))) )
                (  else           (+ (car L) (MrE (cdr L))) )
                )))

Expand and evaluate on paper:
(MrE '( 1 ( 2 ) (3 4) ) )

What does this function do? 
What is a good name for this function?

Classwork/Homework:
0. Sign up for piazza and post a follow up discussion to the Homework thread. (If you didn't get an email by 6pm, and your email is on the homework server, send me an email)

1-3: You should have runnable code in class. You do not need to print it out, you should complete it at home, then send the code to school (via filezilla or some ftp client)
1. Write a function that counts the number of even atoms in a list including its sublists.
(countEvenSub '( 1 (2 3 ) (4 (5 6) ) ) ) -> 3

2. Write a function that counts the number of sublists in a list (including the sublists in the sublists)
(countSublists '( 1 ( ) (2 3) (4 (5 6) ) ) ) -> 4

3. Write a function that counts the number of empty lists in a list (including its sublists)
(countEmptyLists '( 1 ( ) ( ) (4 ( ( )  ) )  ( ) )  ) -> 4


Comments