Assignment 4: Mutual Recursion (due Oct 6)

Assignment 4: Mutual Recursion (due Oct 6)

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.

Reminder that templates are required for each data definition that you use this week.

  1. (6 pts) Sammy's Music wants to reorganize its inventory database. Rather than maintain a list of stock items and assign each album to a single category, the company wants to maintain a hierarchy of categories. Each category can contain several subcategories. Each category also contains the albums which fall into that category. Each album should reside in the most specific subcategory to which it belongs.

    1. (3 pts) Develop a data definition for Sammy's new inventory. The new inventory should maintain the same information about each album as before: title, artist, and prices and copies for each of cds and tapes. You may re-use data definitions from homeworks 2 and 3 where appropriate, but you do not need to.

    2. (3 pts) Write a program get-all-album-categories, which consumes one of your inventories and an album title and returns a list of symbols. The symbols in the output list are the names of all categories and subcategories into which the album falls.

  2. (8 pts) In class, we discussed two data definitions for family trees (reproduced below). Some programs are easier to write using one data organization rather than the other. To explore this, write the following program in each of the two definitions (4 pts each).

    Write a program find-siblings which consumes a list of family trees and a symbol and produces a list of symbols. The symbols in the output list are the names of the siblings of the person named in the input symbol. You may assume that a name appears at most once in a family.

    Notes: This problem uses a list of family trees so that we may have multiple entry points into each family, as discussed in class (for example, in the descendant tree on page 217 of the text, the list would contain the parent structures for Carl, Bettina, and Fred). As a reminder, here are the two data definitions for family trees (the text provides sample pictures of both types of trees, on pages 197 and 217, respectively).

    • Ancestor trees:
      A ftn (for family tree node) is either
        - empty, or
        - (make-child na f m yr ec)
          where na is a sym, f and m are ftn, yr is a num and ec is a sym
      (define-struct child (name father mother year eye-color))
    • Descendant trees:
      A parent is a structure
        (make-parent n y e loc)
      where n and e are symbols, y is a num, and loc is a list-of-children. 
      (define-struct parent (name year eye-color children))
      A list-of-children is either
        - empty, or
        - (cons p loc)
          where p is a parent and loc is a list-of-children

  3. (3 pts) Write a program update-eye-color, which consumes a descendant family-tree (data defn in problem 2) and two symbols (a name and a eye color, respectively) and returns a descendant family tree. In the returned family tree, the named person's eye color is the given eye color. All other information in the family tree should remain the same.

  4. (3 pts) Web sites often include a site-tree, which is a listing of all files available on the web site. A web site is simply a directory hierarchy (as discussed in class, the text has a pictorial example on page 230). A site-tree (sample) contains nested lists of links. Each directory in the web site yields an html-list containing:

    • a link to each file in that directory, and

    • a nested html-list for the site-tree for each directory in that directory.

    Write a program gen-site-tree which consumes a string and produces an html-list. The input string is the path to the directory for which you want to generate the site-tree. The resulting html-list contains the site-tree. For the link to each file, use the file's name as the link text. For the URL, the library provides a function get-path-to-file, which consumes a symbol (file name) and a directory structure and produces a string. Use the result of get-path-to-file as the URL. See the third note below on what the library provides for information regarding the directory that you must pass to get-path-to-file.

    The library provides

    • the data definitions for html (same as in previous assignments)

    • the data definition for directories (the directory definition used is the same as the third model of files and directories given on page 233 of the text)

    • a function create-dir, which takes a path and returns a dir structure for the directory hierarchy starting at the input path. Note that get-path-to-file needs to take the entire directory produced from create-dir as its input.

    Test your program using the library function produce-test-page, which consumes an html-object and a filename, and writes a web page containing the object to the named file.

Kathi Fisler This page was generated on Mon Sep 27 17:01:35 CDT 1999.