Records

Course links

Exercise 1

Write a set of definitions for a record type shirt, to be used in a program that keeps track of the inventory of a clothing store. Provide fields for catalog number, size, color, price, and quantity in stock. Only the last two fields should be mutable. (In other words, you'll need to define the shirt-price-set! and shirt-quantity-set! procedures, but not a shirt-catalog-number-set!, shirt-size-set! shirt-color-set! procedure.)

Exercise 2

Develop a procedure filter-by-color that takes two arguments -- a list ls of records of type compound and a color symbol -- and returns a list of the names of compounds of that color that are elements of ls (just the names, not the compounds themselves!).

Exercise 3

Define a procedure that sorts a vector of records of type shirt into ascending order by catalog number.

Exercise 4

Adapt the binary search procedure so that it takes two arguments -- a vector vec of records of type shirt, sorted by the procedure defined in the previous exercise, and a catalog number catno -- and returns the entire record that contains that catalog number, if there is one in vec, or #f if there is no such record.

Exercise 5

Adapt the procedures that you wrote in exercise 1 to fit a new kind of record, the t-shirt, which has an additional field called text that tells what is printed on the t-shirt.