CS323: PL&M Midterm Practice Exam Prof.: F.S. Annexstein ======================================================================= 1. What are the outputs corresponding to the following Scheme inputs? > (+ (* 5 2) (* 3 4)) > (car '((1 2) (3 4) (5 6))) > (cdr '((1 2) (3 4) (5 6))) > (car (cdr '((1 2) (3 4) (5 6)))) > (cdr (car '((1 2) (3 4) (5 6)))) > (cons 1 '(3 4 5 6)) > (cons '(1 2) '(3 4 5 6)) > (apply-to-all (lambda(x)(- x x )) '(1 2 3 4)) > (filter-in odd? '(1 2 3 4 5)) > (filter-out odd? '(1 2 3 4 5)) > ( (curry* (add1 4)) 5) > (filter-out (curry-eq? 'the) '(the cat in the hat sat)) > (apply-to-all (curry-eq? 'the) '(the cat in the hat sat)) 2. Give a Scheme definition for the predicate APAIR?, that returns true if the argument is a list consisting of exactly two S-expressions. For example, (apair? '( 1 2) ) ==> #t (apair? '( (1 2) 5) ==> #t (apair? '( (1 2) 3 (45))) ==> #f 3. Give a Scheme definition for the MERGE of a pair of sorted lists. For example, (merge '( 1 2 5) '( 3 4 6)) ==> (1 2 3 4 5 6) 4. Give a Scheme definition for the SHUFFLE of a pair of lists. For example, (shuffle '(a b c d) '(w x y z)) ==> (a w b x c y d z) 5. Write an unshuffle procedure that takes as input a single list and returns a list containing a pair of lists which is the inverse of the shuffle function. You may assume that the input list has an even number of elements. For example, > (unshuffle '(1 2 3 4 5 6)) ==> ( (1 3 5) (2 4 6) ) 6. Give a Scheme definitions for the FILTER-OUT and APPLY-TO-ALL as used in the first question. 7. Write a scheme function to curry the operator > (greater than). Use your definition in an example and show its return value. 8. Explain the following Scheme code: (define int-builder (lambda (x) (list x (lambda () (int-builder (+ 1 x )))))) 9, Define ints as follows: (define ints (int-builder 1)). Explain what is the result (of the each of the following: > ints > (car ints) > (cdr ints) > (car (cdr ints)) > ( (car (cdr ints))) > (car ( (car (cdr ints))) ) ============================================================================