Held Wednesday, May 2, 2001
Today we consider how to build records in Scheme. Records group data and
permit access to those data by name.
- For tomorrow, read Object-Oriented
- Are there questions on HW6?
- Script-Fu is not quite Scheme. You can find documentation on
SIOD, the version of Scheme that Script-Fu is based on, at
- I would not recommend that you use both GIMP and CGI for this
assignment. If I can spare the time, I will try to find a
way for you to combine them, but that may take awhile.
- As you've seen in a number of examples, it is often convient to
group data together into what I typically call an
- You currently know two basic ways to group data: lists and records.
- Lists provide dynamic-sized groups of data but have costly access.
- Arrays provide fixed-sized groups of data with quick access to
elements by number.
- However, as we've seen in our work, it is often more convenient
to refer to the parts of a group of data by name.
- For example, given a record for a student, we might ask for the
student's first name, last name, or grade.
- Computer scientists use record as the name for a
fixed-size group of data with quick access to elements by name.
- Unfortunately, Scheme lacks a built-in record type.
- Fortunately, we can implement records on our own.
- The easiest thing to do is to build a vector and treat the elements
of the vector as the fields of the record.
- We write procedures to access each part of the vector.
- However, we'd like to be able to identify whether or not each
vector is supposed to represent one of our desired objects.
- One clever trick is to build a special value that others find
it hard to duplicate and to put it at the front of the vector.
(let ((type-mark (list 'compound)))
(lambda () type-mark)))
let creates a new symbol table with one
entry whose name is
type-mark and whose value
lambda gets that value.
- Any other list of the symbol
compound will be
equal? to the type mark, but not
- Hence, we can use that value.
- Is this ideal? No. Next class, we'll see another way to
build things like records.
Friday, 12 January 2001
- Created generic outline format for class.