Fall '96 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. rac takes a non-empty list and returns its last element.
    ;; (rac '(a b c d)) ==> d
    
    (define rac
      (lambda (ls)
    
    
    
    
    
    
    
      ))
    
  2. rdc takes a non-empty list and returns a new list that is similar, but with the last element removed.
    ;; (rdc '(a b c d)) ==> (a b c)
    
    (define rdc
      (lambda (ls)
    
    
    
    
    
    
    
      ))
    
  3. difference takes two lists of symbols, los1 and los2, and returns a new list similar to los1, but with all symbols that appear in los2 removed.
    ;; (difference '(a b c d e f g) '(d b g)) ==> (a c e f)
    
    (define difference
      (lambda (los1 los2)
    
    
    
    
    
    
    
    
    
    
    
    
    
      ))
    
  4. length* takes a nested list of symbols and returns the total number of symbols in the list at all depths.
    ;; (length* '((a b) c () ((d)))) ==> 4
    
    (define length*
      (lambda (nlos)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
      ))
    
  5. membern? takes a symbol sym, a number n, and a list of symbols los, and returns #t if and only if sym appears at least n times in los.
    ;; (membern? 'a 3 '(a b a c a d)) ==> #t
    ;; (membern? 'a 3 '(a b a c b d)) ==> #f
    
    (define membern?
      (lambda (sym n los)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
      ))
    
Chris Haynes / chaynes@indiana.edu