CS 2135: Lab 3


Lab Motivation and Goals

This lab is designed to help you practice

This lab uses some helper functions that I've provided in library lab3-lib.ss. Download the library to your machine (if you are in lab after 1pm, it may be there already), then use the "Add Teachpack" option under the "Language" menu to load the library. After doing "Add Teachpack", you need to hit "Execute" to make the library functions available to you.


Exercises: Modeling HTML

Consider a restricted subset of HTML containing strings, numbers, symbols, lists, paragraphs, and links:

For purposes of this example, assume that paragraphs can contain other paragraphs and lists, and lists can contain other lists and paragraphs.

  1. Develop a data definition for HTML expressions.

  2. An HTML page consists of a title, a background color, and an HTML expression for the page contents. Develop a data definition for HTML pages.

  3. We want to be able to write HTML pages out to file so that we can view them through a web browser. This proceeds in two stages: first, we need to convert an HTML page into a string, then we need to write that string out to a file.

    Write a function HTML-page-to-string, which consumes an HTML page (in your data definition) and returns a string representing that page. The string should wrap each HTML construct in it's appropriate set of tags. To see the set of tags, view the source of the sample HTML file.

    In writing HTML-page-to-string, you'll probably find the following operations useful:

  4. The library for this lab provides a function write-str-to-file, which consumes two strings and returns void. The first input string is the string to write to file. The second input string is the name of the file to write the first string into. Write a program HTML-page-to-file which consumes an HTML-page and a filename (string) and returns void, but writes the page contents to the named file as a string.

  5. Write a program itemize-lists which consumes an html-page and returns an html-page with the same information, but with all lists itemized (and none numbered).

Exercises: Generating HTML

The following data definitions model the inventory of a music store. The remaining exercises have you generate web pages for the music store using the data definitions you developed in the first part of the lab.

      ;; A music-category is one of
      ;;   - 'classical
      ;;   - 'rock
      ;;   - 'blues

      ;; A music-format is one of
      ;;   - 'cd
      ;;   - 'tape

      ;; An album is a structure
      ;;  (make-album string string music-category)

      (define-struct album (artist title category))

      ;; A format is a structure
      ;;  (make-format music-format number number)

      (define-struct format (type copies price))

      ;; A stock is a structure
      ;;  (make-stock album format format)

      (define-struct stock (album cd tape))

      ;; An inventory is a list of stock

The library provides functions filename-from-symbol and filename-from-string which take a symbol/string (respectively) and return a string containing the given symbol/string with the ".html" extension appended. filename-from-string converts all spaces in the input string to dashes.

  1. Develop a program gen-stock-page which consumes a stock and produces an html-page. The page should contain a separate paragraph for each piece of album data (artist, title, CD price, tape price).

  2. Develop a program produce-all-stock-pages which consumes an inventory and returns true. The program writes one web page file for each stock item in the inventory. Use filename-from-string or filename-from-symbol to create the filename for each stock's page.

  3. Develop a program gen-inventory-index-page which consumes an inventory and returns an html-page. The page should contain a list of links, with one link for each stock item in the inventory. Use the album title as the text in the link and the library function filename-for-string to compute the filename for the stock's web page.

  4. Listing all of Sammy's inventory on one web page makes it harder for customers to browse categories of music. We therefore want to create separate listings for each category. The remaining problems generate such a web site.

    1. Develop a program produce-category-page which consumes a category and an inventory and returns true. The program should write to file a page containing a list of links to the stock items that are in that category.

    2. Develop a program produce-all-category-pages which consumes a list of categories and an inventory and returns true. The program should create the category page for each category in the input list. Note that for this program, you do not need to look at what kind of inventory you have; instead, your template needs only to take the structure of the list of categories into account.

    3. Develop a program produce-category-index which consumes a list of categories and returns true. The program should write to file a page containing a list of links, one to each category page.