Fundamentals of Computer Science I (CS151.01 2006F)

Lab: Records in Scheme

This lab is also available in PDF.

Summary: We investigate records in Scheme through experiments with a record for chemical compounds.

Contents:

Exercises

Exercise 0: Preparation

a. Start DrScheme.

b. Make a copy of compound.scm.

c. Scan through that file to make sure that you understand all the procedures.

Exercise 1: Testing Compounds

a. Try the compoound examples given in the reading on records to see if they behave we I said they would.

b. Try a few of your own variations.

c. Explain why the attempted fake is not listed as a compound. Hint: Think about the order of the let and lambda in compound-type-mark.

Exercise 2: Selecting Compounds

Define a procedure, select-by-color, that takes two arguments -- a list, compounds, 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 compounds.

Exercise 3: Falsifying Compounds

a. Can you set the melting point of a compound to an illegal temperature? If so, how? If not, why not? (Note that there are other ways to modify compounds than to use the record's provided procedures.)

b. Find a way to make a vector that compound? identifies as a compound. You may not use make-compound or compound-copy to build your new vector. However, you may use either procedure to create a helper compound from which you copy values.

Exercise 4: A Shirt Record

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, intended gender of wearer, size, color, price, and quantity in stock. Only the last two fields should be mutable.

Exercise 5: Searching Shirts

Adapt the binary search procedure so that it takes two arguments -- a sorted vector, vec, of records of type shirt 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.

For Those With Extra Time

Extra 1: Sorting Shirts

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

Extra 2: Comparing Records

Write an expression that, through an appropriate call to mergesort, sorts a list of shirts by catalog number.

Extra 3: Sorting Shirts, Revisited

Rewrite your answer to the first sorting problem by using your answer to the previous problem.

 

History

 

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Thu Nov 30 21:43:08 2006.
The source to the document was last modified on Sun Nov 19 16:59:12 2006.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2006F/Labs/records.html.

You may wish to validate this document's HTML ; Valid CSS! ; Creative Commons License

Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright © 2006 Samuel A. Rebelsky. This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.