Keith's Amazingly Supplementary Quiz One Review ADDENDUM ======================================================== Oops!! Sorry about this, folks, I had forgotten to include one more important topic for which you are responsible on quiz one. (I originally had it in my quiz two review packet...) 9. Manifest types, Data-directed programming and Message passing I have included a sample problem involving manifest types and data-directed programming, but do not have much material on message passing that doesn't deal with material from this week (e.g.: state, environments, and OOPS with inheritance, for which you are NOT responsible.) Hope the information helps. DATA-DIRECTED PROGRAMMING Consider a weather database, which monitors weather conditions for a local area. This database might keep track of information such as temperature, precipitation, and wind speeds. The Boston info can be retrieved from either Boston University, Harvard, or MIT. However, each of these schools keeps track of this information in a different manner. For example, while Boston University can't tackle anything more difficult than the standard units most Americans use, such as degrees Farenheit and miles-per-hour, Harvard is trying to be politically correct, and uses the metric system, while MIT is its usual geeky self, and uses engineering measurements like degrees Kelvin, and meters-per-second. Because we're cool MIT people, we don't like to do any more thinking than is necessary, so we prefer the standard units of measurement. Therefore, we have the following procedures to do conversions for us: (define (cm-to-in dist) ...) (define (in-to-cm dist) ...) (define (mm-to-in dist) ...) (define (in-to-mm dist) ...) (define (kel-to-faren temp) ...) (define (faren-to-kel temp) ...) (define (cent-to-faren temp) ...) (define (faren-to-cent temp) ...) (define (kph-to-mph speed) ...) (define (mph-to-kph speed) ...) (define (mps-to-mph speed) ...) (define (mph-to-mps speed) ...) The information is stored in lists of different formats, depending on who the weatherman is that day (and where he went to college), so each format has to maintain a tag at the front of it, indicating whether it is in standard format (tagged with an "S"), metric format (with an "M"), or engineers' format (with an "E"). The order of information in a list, however, is not consistent: since MIT folk have longer to walk, our primary concern is the wind speeds. Therefore, the engineers' format has wind speed listed as its first item. BU students are afraid of messing up their hair, so they are chiefly concerned with the precipitation. The complete ordering of information can be seen by these constructors (note, the information given as arguments is always provided in standard format, so conversions must be made): (define (make-standard-format temp precip wind) (list 'S precip wind temp)) (define (make-metric-format temp precip wind) (list 'M temp precip wind)) (define (make-engineer-format temp precip wind) (list 'E wind temp precip)) (define (MIT-weather temp precip wind) (make-engineer-format (mph-to-mps wind) (in-to-mm precip) (faren-to-kel temp))) etc. In order to facilitate the maintenance of this data, the designers of the weather database (no, it wasn't Ben Bitdiddle, or any of those bozos) decided to use a data-directed approach, so that the various data could be easily retrieved, no matter what format it was recorded in. 1. Assume the procedures to recover the temperature for each of these three formats is defined as follows (note, as with feeding the information, let's assume that we're cool, so we return all information in standard format--this way we don't have to think as much. After all, that's what MAKES us cool...): (define (standard-temp weather) (cadddr weather)) (define (metric-temp weather) (cent-to-faren (cadr weather))) (define (engineer-temp weather) (kel-to-faren (caddr weather))) Write procedures to get the rainfall and windspeed of each of the three formats as well. 2. Given these procedures, install them into a 3x3 "table", using the ``put'' statement you know so well. 3. Write a generic procedure, called ``get-temperature'', which determines the temperature, in degrees Farenheit, for any weather data object. Do the same for rainfall, with ``get-rainfall'', and wind speed, with ``get-windspeed''. 4. In New York, they have a system similar to that of Boston, except that their weather system implementers came from a trade school, and used simple message passing to implement their generic system. Specifically, they create a weather object, and pass it a message such as ``rainfall'', or ``temperature'', and it returns the appropriate data in standard units, regardless of the type of weather object. Describe the advantages and/or drawbacks of the New York system, versus the Boston system. Where would you rather be employed?