CSC 151-02, Fall 2006 : Schedule : Homework 14


Homework 14: Interest Groups

Assigned: Tuesday, 7 November 2006
Due: Friday, 10 November 2006
No extensions!

Summary: In this assignment, you will explore a variant mechanism for searching lists.

Purposes: To help you think more about association lists and linear search.

Expected Time: One to two hours.

Collaboration: You may work in a group of any size between one and four, inclusive. You may consult others outside your group, provided you cite those others. You need only submit one assignment per group.

Submitting: Email me your work, using a subject of CSC151 Homework 14.

Warning: So that this exercise is a learning assignment for everyone, I may spend class time publicly critiquing your work.

Background

Student government at Egelloc College has been gathering information on the dozens of student groups that they support. For each group, they have two values: the name of the group and a list of all the nicknames of students in the group. (Amazingly, no two students at Egelloc have the same nickname.) They've chosen to represent groups as strings and nicknames as symbols.

They've decided to represent each group as a list with two elements: the first is the name, the second is a list of student nicknames. To keep track of all of the student groups, they've put them into a list. For example,

(define student-groups
(list
(list "s&b" (list 'nick 'sheng 'saugar))
(list "hackers" (list 'nick 'eryn 'cable 'ted 'emily))
(list "swing dance" (list 'eryn 'old-ian 'leila))
(list "singers" (list 'leila 'jan 'jim 'vincent 'singing-dan 'jack))
(list "teecees" (list 'eryn 'jan 'young-ian))
(list "soccer" (list 'hugh 'alex))
(list "math" (list 'steffii 'josh))
(list "Seattlites" (list 'janet 'ian-b))))

Now they want ways to process the list.

Assignment

Write a procedure, (groups nickname) that, given someone's nickname and a list of all student groups in the form mentioned above, returns a list of all the groups to which that student belongs.

> (groups 'eryn)
("hackers" "swing-dance" "teecees")
> (groups 'sam)
()


Janet Davis (davisjan@cs.grinnell.edu)

Created November 6, 2006 based on http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2006F/Homework/hw.13.html
Last modified November 7, 2006
With thanks to Sam Rebelsky