Assignment 6: Functional Abstraction (due Oct 20)



Before you tackle the homework, remind yourself of our General Advice, Advice on Homeworks, and Grading Guidelines. Above all, keep your work neat and honest.


Use templates on all abstract functions that you define this week. You do not need templates for functions that simply call your abstract functions. Be sure to write contracts and purpose statements for all functions, however.

Note: For the following problems, you may not use Scheme's built-in abstract functions, such as filter, map, and fold. If you wish, you may define and use your own versions of these functions; you are not, however, required to do this.

  1. (5 pts) Consider the following two programs (the first is from the first exam, the second is a variation on a problem from the first exam).
    (define (only-two-syms? sym1 sym2 alos)
      (cond [(empty? alos) true]
    	[else (and (or (symbol=? sym1 (first alos))
    		       (symbol=? sym2 (first alos)))
    		   (only-two-syms? sym1 sym2 (rest alos)))]))
    
    (define (all-alive? aloc)
      (cond [(empty? aloc) true]
    	[else (and (> (character-lives (first aloc)) 0)
    		   (all-alive? (rest aloc)))]))
    
    1. (3 pts) Write an abstract program that captures both of these definitions.

    2. (2 pts) Provide new definitions of only-two-syms? and all-alive? in terms of your abstract program.

  2. (5 pts) Consider the following two programs
    (define (double-last alon)
      (cond [(empty? (rest alon)) (* 2 (first alon))]
    	[else (double-last (rest alon))]))
    
    ;; The function max is built-in in DrScheme
    (define (max-of-list alon)
      (cond [(empty? (rest alon)) (first alon)]
    	[else (max (first alon) (max-of-list (rest alon)))]))
    
    1. (3 pts) Write an abstract program that captures both of these definitions.

    2. (2 pts) Provide new definitions of double-last and max-of-list in terms of your abstract program.





Kathi Fisler This page was generated on Wed Oct 13 11:18:11 CDT 1999.