Spring '97 C311 Quiz

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

  1. replace replaces each top-level item in a list of items ls by a given item new-item.
    ;; (replace 'yes '(do you like ice cream)) ==> (yes yes yes yes yes)
    
    (define replace
      (lambda (new-item ls)
    
    
    
    
    
    
    
      ))
    	  
  2. iota takes a number n and returns a list with n numbers from 0 to n-1.
    ;; (iota 5) ==> (0 1 2 3 4)
    
    (define iota
      (lambda (n)
    
    
    
    
    
    
      ))
    	  
  3. swapper takes three arguments: an item x, an item y, and a list ls. It builds a new list in which each top-level occurrence of x in ls is replaced by y, and each top-level occurrence of y in ls is replaced by x.
    ;; (swapper 'cat 'dog '(my cat eats dog food)) 
    ;;  ==> (my dog eats cat food)
    
    (define swapper
      (lambda (x y ls)
    
    
    
    
    
    
    
    
    
      ))
    	  
  4. all-same? takes a list ls as its argument and tests whether all top-level elements of ls are the same.
    ;; (all-same? '(a a a a a)) ==> #t
    ;; (all-same? '(a b a b a)) ==> #f
    
    (define all-same?
      (lambda (ls)
    
    
    
    
    
    
    
      ))
    	  
  5. max* receives a non-empty (and possibly deep) list of numbers ls and returns the greatest number in the list.
    ;; (max* '((-21 -24 -25) ((2 3 5 7 11 13) (10 20)) 14)) ==> 20
    
    (define max*
      (lambda (ls)
    
    
    
    
    
    
      ))
    	  
Chris Haynes / chaynes@indiana.edu