;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname lab8-starter-file-2) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f))) ; Starter file, Part 2 (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)) ; LIBRARY FUNCTIONS ----------------------------------------------------------- ; drop : String [Listof String] -> [Listof String] ; Remove all occurrences of the given element from the list, if it is present. (define (drop str los) (filter (λ(x) (not (string=? str x))) los)) (check-expect (drop "hi" '()) '()) (check-expect (drop "hello" '("cats" "are not that affectionate")) '("cats" "are not that affectionate")) (check-expect (drop "cats" '("cats" "hi" "i" "still" "love" "cats" "lots")) '("hi" "i" "still" "love" "lots")) ; count : String [Listof String] -> Number ; Count how many times the given string appears in the list. (define (count str los) (foldr (λ(x y) (if (string=? str x) (+ y 1) y)) 0 los)) (check-expect (count "hi" '()) 0) (check-expect (count "hello" '("cats" "are great")) 0) (check-expect (count "cats" '("cats" "hi" "i" "love" "cats" "lots")) 2)