6.001 Recitation – Feb 26, 2003

 

RI: Konrad Tollmar

 

• Pop Quiz

 

0. ‘(say your name)

 

 

1. Warm-up

                                                                 Value                                  Type

-------------------------------------------------------------

 (define (three) 3)

-------------------------------------------------------------

three

-------------------------------------------------------------

(three)

-------------------------------------------------------------

(define four 4)

-------------------------------------------------------------

four

-------------------------------------------------------------

(four)

-------------------------------------------------------------

(+ (three) four)

-------------------------------------------------------------

(define (add-x x)

           (lambda (y) (+ y x)))

-------------------------------------------------------------

(define add-10 (add-x 10))

-------------------------------------------------------------

(add-10 5)

-------------------------------------------------------------

 

2. Procedures

Given the procedure,

 

(define apply-to-3-and-4

   (lambda (p) (p 3 4)))

 

What choices for <exp> in a combination of the form (apply-to-3-and-4 <exp>) will cause the following numbers to be returned?

 

a. --> 7  , <exp> = 

b. --> 1  , <exp> = 

c. --> 2  , <exp> = 

d. --> 3  , <exp> = 

e. --> 4  , <exp> =  

 


3. Recursive procedures

Someone, by misstake i guess, redefined the standard + and – procedures (among many other procedures). Write a new recursive add procedures by only using the =,  inc and dec procedures.

 

 

 

 

 

 

 

 

 

 

 

4. List procedure

Write a process version of a procedure called remove that takes a number and a list and returns a new version of the list where that number is no longer an element.