ICS H21 • UC IRVINE • DAVID G. KAY • FALL 2008

Lab Assignment 5


This assignment is due at the end of lab on Friday, October 31.

Choose a partner for this assignment, someone you haven't worked with already. Starting with this assignment, change your language level to Intermediate Student with Lambda.

(a) Do exercises 15.3.1, 15.3.3, and 15.3.4.

Do exercise 17.6.1 and one exercise chosen from 17.6.2 through 17.6.6. (If you choose 17.6.2, write the reveal-list function, but it's not necessary to do the part of the problem where you use the hangman.ss teachpack to make a complete Hangman game, since that depends on a problem that was not assigned previously.)

Do exercises 17.7.1, 17.7.2 (just parts 1, 3, and 5), 17.7.3, and 17.7.4. Then do exercises 17.8.3 and 17.8.5.

Do exercises 19.1.4, 19.1.5, 19.1.6, and 19.2.2.

Collect these definitions and submit them as usual via Checkmate.

(b) A recipe is a structure

   (make-recipe T IL SL)

where T is the title (a symbol), IL is a list of ingredients, and SL is a list of steps.

An single ingredient is a symbol (like 'eggs); a single step is a list of symbols (like '(beat the eggs)). A recipe contains a list of ingredients and a list of steps; for example:
(make-recipe 'ThaiIcedCoffee
   '(coffee sugar condensed-milk ice)
   '((brew coffee) (add sugar and condensed-milk) (pour coffee mixture over ice)))

(b.1) Write the structure definition for a recipe, using "title," "ingredients," and "steps" as the names of the fields.

(b.2) Some people say that any recipe can be improved by the addition of chocolate. (Others say sesame oil, or Tabasco sauce.) Write a definition of add-special-ingredient. You may use an auxiliary function if you like.
; add-special-ingredient: list-of-recipes symbol -> list-of-recipes
; Return a list containing all the recipes in the input list, but with the symbol added
; at the beginning of the ingredients list of each recipe.

(b.3) Write a definition for complete-ingredients-list.
; complete-ingredients-list: list-of-recipes -> list-of-symbols
; Return a list containing all the ingredients from all the recipes in the list,
; with no duplications. (You may assume that all the elements of a single
; ingredients list are unique.)

[Hint: Define an auxiliary function called add-unique.]

(b.4) Sometimes we have to substitute one ingredient for another in a recipe. Write a definition for replace-ingredient as described below. Auxiliary functions are essential here.
; replace-ingredient: symbol1 symbol2 recipe -> recipe
; Return a recipe like the input, but with every instance of symbol1 replaced by symbol2,
; both in the ingredients list and in the list of steps.
; Example: Suppose TIC is the Thai Iced Coffee recipe defined above.
; (replace-ingredient 'coffee 'decaf TIC) would return
; (make-recipe 'ThaiIcedCoffee
;   '(decaf sugar condensed-milk ice)
;   '((brew decaf) (add sugar and condensed-milk) (pour decaf mixture over ice)))

(b.5) Some recipes are so complex that they include in their steps some references to other recipes. A cake recipe in a cookbook, for example, might have as one step, "Use the chocolate icing recipe on page 23." To reflect this in our Scheme recipes, we change our definition of a "list of steps":

A list of steps (LOS) is either

  1. empty;
  2. (cons S LOS), where S is a single step (i.e., a list of symbols); or
  3. (cons R LOS), where R is a recipe.

Write a definition for complete-ingredients-list2 that accommodates these (possibly nested) recipes.
; complete-ingredients-list2: list of valid recipes -> list of symbols
; Return a list containing all the ingredients from all the recipes in the list,
; including nested recipes, with no duplications. (You may assume that
; all the elements of a single ingredients list are unique.)

Collect all of these definitions and submit them via Checkmate.

(c) Suppose we change our restaurant structure so that instead of just one best dish and its price, each restaurant has a menu of dishes. So a rrant is now

   (make-rrant name cuisine phone menu)

where name, cuisine, and phone are strings and menu is a list of dish structures:

   (make-dish name price)

where name is a string and price is a number.

None of these modifications should require any change to the code for collections.

(c.1) Make up a big list of rrant structures to use in your testing. Trade and combine lists with your classmates.

(c.2) Download version 1d of the restaurants program. Spend some time studying it; it's a version that includes the erase and adjust commands, plus binary search trees using lazy deletion.

Make a copy of the restaurants1d.scm program and call it restaurants1e.scm.

(c.3) Modify the program to handle rrant objects that include menus as described above. You should try at least to make a list of all the changes you will need before looking at our checklist of modification steps.

(c.4) Modify the program to display the average price (of all the dishes on the menu) whenever a restaurant is printed.

(c.5) Add a command to the main menu that allows the user to search for (and display) all the restaurants that serve a given cuisine along with the average price of (all the menus of the restaurants that serve) that cuisine.

(c.6) Add a command to the main menu that allows the user to search for (and display) all the restaurants that serve a dish containing a given word or phrase. (This is more realistic than forcing the user to type the exact name of the dish; here, the user can just type "fava beans" and match all the dishes that include that phrase. We've provided some code for string processing to make this task easier.)

Collect all of these definitions and submit them via Checkmate.

(d) No extra credit for this week; sorry! Use the time to study for your other midterms.

(e) Remember that each partner must complete a partner evaluation form on eee.uci.edu.


Based in part on ICS H21assignments and exams by David G. Kay from Fall 2001; modified by David G. Kay, Fall 2004–Fall 2008.


David G. Kay, kay@uci.edu
Friday, October 24, 2008 7:03 AM
ÿ