CSC 326 Assignment 5
Set operations in Scheme
Fall 1999
Due: December 1, 1999
This assignment is essentially exercise 10.7 in your textbook, with more detailed specification.
Suppose that sets are defined using Scheme lists, where each element of a set appears exactly once in its list. Define Scheme procedures that implement the following operations. Operation names are in bold, parameters in italics.
member? |
element |
set |
Result is #t if element is a member of the set and #f otherwise |
union |
set1 |
set2 |
Result is a set which is the union of the two sets. |
intersection |
set1 |
set2 |
Result is a set which is the intersection of the two sets. |
difference |
set1 |
set2 |
Result is a set which is the difference of the two sets (elements that are in first set but not second). |
Your procedures can assume that the arguments passed to them are valid elements / sets.
To turn in: Store the procedure definitions in file set.ss. To submit, copy set.ss to your eccentric upload folder for CSC 326.
Your code must be documented. The semicolon (;) in Scheme is equivalent to // in C++ for indicating comments. Make sure your name, assignment, course, etc, at the top of the file. Also descriptive comments for each procedure.
Define as many auxiliary procedures as necessary. My solution to this problem consisted of six procedures comprising about 30 "lines" of code in total. Recursion for list processing is required. Side effects are not allowed (e.g. assignment). My solution did use the built-in append procedure but otherwise was constructed using only define, cond (or if), cons, car, cdr and auxiliary procedures. I expect a similar approach from you.
You can obtain the latest version of Dr. Scheme from \\eccentric\download\csc326\Dr Scheme 101 download\plt.exe. This is the Win95/98/NT installation file. You can also download it directly from Rice University at http://www.cs.rice.edu/CS/PLT/packages/drscheme/. The install file is about 3MB long.
If you do not have a PC available, I have installed Dr. Scheme on five PCs in Cheek 213. They are 213-06 through 213-10 (the column of PCs against the other side of the partition). It is in C:\Program Files\PLT\DrScheme.exe.
If command prompt shows "Beginning Student", change it to "Advanced Student" using the "Choose Language" item from DrScheme's Language menu, then click the "Execute" button to get a fresh command prompt.
Chapter 10 of your textbook should be sufficient reference for this project, but additional resources are available from the Dr. Scheme web site and other sources.
[Assignments | CSC 326 | Peter Sanderson | Computer Science | SMSU ]
Last reviewed: 24 November 1999
Peter Sanderson ( PeteSanderson@mail.smsu.edu )