CISC-280 Program Development Techniques

Homework 7: Data Directed Programming Practice and more

Due: Tuesday, November 11, 2008

NOTE: there will be no lab on Monday, November 10th.  This homework is in place of that lab. Sophie will hold office hours during the normal lab times.

1. Data-directed Programming Practice (20 points) - This problem is largely one developed by Prof. Decker.

Using the support code from chapter two and the class notes which can be found in the file hw6-data-directed.ss, create and use a table in the data directed approach to generic procedures for the following problem involving two different types of food: wine and cheese. 

Develop two data structures, one to represent WINE and one to represent CHEESE (both of these foods can be represented as simple list structures).

Each wine has a NAME, PRICE, TYPE [one of  'red 'white], and SWEETNESS [one of 'dry 'semi-dry 'sweet].
Each cheese has a PRICE, NAME, and TYPE [one of 'mild 'sharp 'blue 'smoked]

Develop a data-directed package for each data type. PUT and GET have been implemented for you. Your external interface should look something like this:

;;; EXTERNAL INTERFACE
(define (price thing) (apply-generic 'price thing))
(define (name thing) (apply-generic 'name thing))
(define (type thing) (apply-generic 'type thing))
(define (sweetness thing) (apply-generic 'sweetness thing))
(define (compatible? thing1 thing2) (apply-generic 'compatible? thing1 thing2))
(define (make-cheese name price type) ((get 'make-food 'cheese) price name type))
(define (make-wine name price type sweetness) ((get 'make-food 'wine) name type price sweetness))

Develop the function compatible? that tells if two foods are compatible. The unique thing about this function is that it can work with two cheeses, or two wines, or a wine and a cheese.  Two cheeses are always compatible. Two wines are compatible if thier sweetness levels are equal. A wine is compatible with a cheese if the wine is red and the cheese is blue, or if the wine is white and the cheese is mild. (Caution: don't actually follow these rules at your next wine-and-cheese-bash :-)

There will be some difficulty in getting compatible? to work properly with args of different types. In particular, not all versions of compatible? will reside in the install procedures that you make. First, make sure that you do as much work as possible within the individual packages. Secondly, discuss the difficulty you had in implementing compatible? with multiple types and what it might mean for very large software systems.

Develop an applications level  function print-list that takes a list of foods of different types and prints out the name and price of each.  You may find it useful to use the scheme function display for doing the actual printing.

2. Bringing it together: Based on Exercise 2.76, page 187.  (10 points)

 As a large system with generic operations evolves, new types of data objects or new operations may be needed. For each of the three strategies -- generic operations with explicit dispatch (as seen in section 2.4.2), data-directed style, and message-passing-style -- describe the changes that must be made to a system in order to add new types or new operations. Describe any special constraints (e.g., in naming operations/types) that must be abided by in order for the newly implemented types/operations to work. Which organization would be most appropriate for a system in which new types must often be added? Which would be most appropriate for a system in which new operations must often be added?