Nested Sets (team assignment)

In a previous assignment, you wrote code to represent sets as lists. In general sets can contain other sets. Revisit the sets problem and construct new code to allow sets to contain other sets. For example:

(set-equal? '(1 (2 3)) '((3 2) 1)) ---> #t
(set-equal? '(1 2 3) '((3 2) 1)) ---> #f
(set-equal? '(1 2 3) '((1 2 3))) ---> #f
(union '(1 (2) 3) '(3 2 1)) ---> (1 2 3 (2))
(union '((1 2 3)) '((3 4 5))) ---> ((1 2 3) (3 4 5))
(union '((1 2 3)) '((3 2 1))) ---> ((1 2 3))
(intersect '((1 2 3)) '((3 2 1))) ---> ((1 2 3))
(intersect '((1 2 3)) '((4 5 6))) ---> ()
(intersect '((1) (2) (3)) '((2) (3) (4))) ---> ((2) (3)) 

Make sure to test additional cases of sets containing sets containing sets, etc. You should allow arbitrary levels of nesting.

This was originally an individual assignment. It is perfectly ok to start with the code that one of you used. Indicate in program comments whose code you used. Alternatively, feel free to start from scratch if you want to truly create an effort between the two of you.


You must use recursion, and not iteration. You may not use side-effects (e.g. set!).

Submit your code in a file called nestedsets.scm.