C311: Quiz

Write the following Scheme procedures. You have thirty minutes. Follow the cardinal rules of indentation, and use any extra time to check your work.

  1. interleave takes two flat lists of equal length, and interleaves their elements, starting with the first element of the first list.
    (interleave '(a b c) '(1 2 3)) ==> (a 1 b 2 c 3) 
    
  2. count-parens takes a nested list structure and returns the number of parentheses in the printed form of the list.
     
    (count-parens '((a b) (c) ((d)) c)) ==> 10
    (count-parens '()) ==> 2
    
  3. infix->prefix takes an expression that is in infix notation and returns a Scheme expression that has the same value. Assume that only the binary operators /, +, *, and - are used.
    (infix->prefix '((a + b) / 4)) ==> (/ (+ a b) 4)
    (infix->prefix '((1 + x) - ((y * 4) / (z - 5))))  ==>
                                    (- (+ 1 x) (/ (* y 4) (- z 5)))
    
  4. types-all takes a nested list structure containing symbols, numbers, booleans, characters, and strings, and returns a list structure of the same shape in which every non-list element is replace by its type. Recall that the predicates for types are symbol?, number?, boolean?,char?, and string?
    (types-all '(sym1 (sym1 (#f 1) #\a) "string")) ==>
                (symbol (symbol (boolean number) character) string)
    
chaynes@indiana.edu