On this page:
2.12.1 Objectives
2.12.2 Exercises (due 2011/  10/  26 08:  45:  00)
2.12.3 Optional Exercises (due 2011/  10/  31 08:  45:  00)
2.12.4 Practice Exercises
2.12.5 Notes

2.12 Lists of Objects

When you are listing

You should be aux-ing also

Especially with compounds

2.12.1 Objectives

At the end of this class, you should know:

At the end of this class, you should be able:

2.12.2 Exercises (due 2011/10/26 08:45:00)

1. Develop data definitions for ListOfCourse and Course (number, department, name, etc), write a function upperLevelCourses that consumes a list of courses and a department and produces a list of all courses at the 300- or 400-level offered by that department.

2. A phone directory combines names with phone numbers. Develop a data definition for phone records and directories. Using this data definition develop the function, whoseNumber, which returns the name that goes with some given phone number and phone directory.

3. Using the notes from class (if you want), develop the function recall, which consumes the name of a toy ty and an inventory and produces an inventory that contains all items of the input with the exception of those labeled ty.

4. Write a function, append, which takes two lists of numbers and returns a list of numbers where every element of the first list is before every element of the second list. For example,

append(

 new OneMoreNumber(1, new OneMoreNumber(2,

      new EmptyListOfNumbers ())),

 new OneMoreNumber(3, new OneMoreNumber(4,

      new EmptyListOfNumbers ()))

) =

 new OneMoreNumber(1, new OneMoreNumber(2,

      new OneMoreNumber(3, new OneMoreNumber(4,

           new EmptyListOfNumbers ()))))

2.12.3 Optional Exercises (due 2011/10/31 08:45:00)

5. Develop the function breakup which consumes a phone directory and a boyfriend and returns a phone directory without the scum bag’s number in it.

6. Using the notes from class, develop the function nameRobot, which consumes an inventory and produces an inventory with more accurate names. Specifically, it replaces all occurrences of robot with r2d3.

2.12.4 Practice Exercises

7. Develop the function phoneNumber, which returns the phone number that goes with some given name and phone directory.

8. Using the notes from class (if you want), develop the function extractMoreThan1, which consumes an inventory and creates an inventory from those records whose prices are above one dollar.

9. Develop the dual of recall, only which returns an inventory consisting only of the given toy

2.12.5 Notes

These notes are primarily for my sake, but I don’t see any reason to hide them from you.

inventory record (name, price)

 

sumInventory : inv -> nat

 

containsDollHuh : inv -> boolean

 

priceOf : name inv -> price

 

extract1 : inv -> inv (less than $1)

 

tax : inv -> inv (prices raised by 5%)