On this page:
Modifications
Code Review
6.11.0.4

-

home work!

1 Program Design Via Iterative Refinement 2

Purpose Surprise! There’s more to this lab.

not that kind of doctor

Modifications

10 minutes

The social network architects have collected user feedback and determined that their representation of a User is too rigid. Some users have more than just friends and enemies; some actually care about football (the real one, not the American kind) and work (who’d have known), and they do want to be able to classify their connections in this nuanced manner.

So, the architects have given users the ability to create their own set of customized groups, using the new data types Group and GroupName. The User data definition has also been updated accordingly.

Start with this file, which includes the following data definitions and examples, as well as the same library functions from before (which may still come in handy).

(define ENDS "Friends")
(define MIES "Enemies")
(define WORK "Work")
(define TEAM "Football Team")
(define GROUPS `(,ENDS ,MIES ,WORK ,TEAM))
 
(define-struct group [name people])
(define-struct user [name groups])
 
; A SocialNetwork (SN) is a [Listof User].
; A Group is a (make-group GroupName [Listof String])
; interpretation name is the type of group, and
; people is the names of the users in that group.
; A GroupName is on GROUPS.
 
; A User is a (make-user String [Listof Group])
; interpretation name is the user's name, and
; groups is a list of their groups of connections.
 
; examples
(define amanda-ends (make-group ENDS '("Carlo" "Diya" "Fran")))
(define amanda-team (make-group TEAM '("Fran")))
(define amanda (make-user "Amanda" (list amanda-ends amanda-team)))
 
(define bruce-ends (make-group ENDS '("Carlo" "Diya" "Emmi" "Fran" "Han")))
(define bruce-mies (make-group MIES '("Fran" "Diya" "Carlo")))
(define bruce-work (make-group WORK '("Carlo" "Amanda" "Diya" "Gregg")))
(define bruce (make-user "Bruce" (list bruce-ends bruce-mies bruce-work)))
 
(define clo-team (make-group TEAM '("Amanda" "Fran")))
(define clo-ends (make-group ENDS '("Diya" "Han")))
(define clo-mies (make-group MIES '("Amanda")))
(define clo-work (make-group WORK '("Amanda")))
(define carlo (make-user "Carlo" (list clo-team clo-ends clo-mies clo-work)))
 
(define diya-ends (make-group ENDS '("Emmi" "Fran" "Han")))
(define diya-mies (make-group MIES '("Fran" "Carlo")))
(define diya-work (make-group WORK '("Carlo" "Amanda")))
(define diya (make-user "Diya" (list diya-ends diya-mies diya-work)))
 
(define emmi-ends (make-group ENDS '("Fran" "Han")))
(define emmi-team (make-group TEAM '("Carlo")))
(define emmi-mies (make-group MIES '("Carlo" "Diya" "Bruce" "Fran" "Han")))
(define emmi (make-user "Emmi" (list emmi-ends emmi-team emmi-mies)))
 
(define fran-ends (make-group ENDS '("Gregg" "Han")))
(define fran-mies (make-group MIES '("Amanda" "Bruce" "Carlo")))
(define fran (make-user "Fran" (list fran-ends fran-mies)))
 
(define gregg-mies (make-group MIES '("Han" "Bruce" "Fran")))
(define gregg-team (make-group TEAM '("Amanda" "Emmi")))
(define gregg-work (make-group WORK '("Amanda" "Carlo" "Diya")))
(define gregg (make-user "Gregg" (list gregg-mies gregg-team gregg-work)))
 
(define han-ends (make-group ENDS '("Gregg")))
(define han-mies (make-group MIES '("Bruce" "Carlo")))
(define han (make-user "Han" (list han-ends han-mies)))
 
(define SN1 (list amanda bruce carlo diya emmi fran gregg han))

As you know from the lectures and the ever-evolving Gobbler game, the first step of design by refinement is to adjust of the existing code to the new data definitions.

Exercise 1 Revise your existing functions so that they work with the new data. It is important to recognize that the data definition has gotten significantly more complicated. A SocialNetwork was previously a list of structs with two list fields (friends and enemies), but it is now a list of structs (users) with a field that is a list of structs (groups) with a list field (people). Phew.

Consider the functions remove-user and count-friendships, which you just designed. Working top-down, develop a wish list of the helper functions you think you will need in their updated versions. The data definition guides you. (Use the template, Luke.) — Write down a signature and purpose statement for each one. Consider which parts of your well-tested program you can reuse. You should be able to do this even if you did not complete the previous exercises.

Note In your final redesign, you may not need to explicitly name and write out all of these functions, but it is important to consider every distinct data transformation that will help produce the final answer.

Code Review

10 minutes

The Teaching Assistants will pick one pair who will explain their plan to their lab mates, following the design recipe steps.