CISC-280 Program Development Techniques
In this assignment you will use the idea of Data-Directed Programming to produce generic procedures for operating on sets. In the text, three different representations of sets are discussed. For this assignment we will concentrate on just two of them:: unordered list representation and ordered list representation. You should use the tags unordlst and ordlst to tag sets using the two representations.
For each representation, you will need the following functions. You will need to write the make-set functions but the other functions can be found in the scheme file associated with Slides11 which can be found here.
(make-set lst) - takes a list of numbers (you may assume with no duplicates), and returns a set (in the appropriate representation).
(element-of-set ele set) - takes a number (ele) and a set of numbers, and returns #t if ele is in the set.
(adjoin-set ele set) - takes a number (ele) and a set of numbers, and returns a set composed of the original set with ele added (provided it wasn't already in set).
(intersection set1 set2) - takes two sets of numbers and returns a set containing the elements common to both.
(union set1 set2) - takes two sets of numbers and returns a set containing the elements in either one or the other.
Using the support code from chapter two and the class notes which can be found in the file hw6-data-directed.ss, create and use a table in the data directed approach to generic procedures. Install, define the general functions by calling apply-generic, and then call the procedures written in Part 1 on sets formed by both representation choices. (This means you may wish to retain two different make-set functions in order to get sets in the different representations.) You may assume for this exercise that we only perform an operation on two sets of the same type.
Remember that you can use procedures from a separate scheme file by calling (load "aux-file-name.scm")
Write procedures in the message passing style for adjoin and union for sets represented as ordered lists. You may assume that a set to be passed to union is of the same type.