Assignment 8a
Due Date: Monday at 9:00pm (Week 8)
Submit two files: one file for exercises 1 and 2, and a separate file with your Forum project. (To submit two files on the handins server, select the two files and zip them together, then submit the zip file.)
Purpose To practice designing functions on lists, and extending and refining earlier programs.
Finger Exercises Complete Lab 6 Creating Abstractions.
Exercise 1 Consider the following data definitions:
(define-struct tweet [author text]) (define-struct image-tweet [author text image]) (define-struct retweet [author tweet]) ; A Tweet is one of: ; - (make-tweet String String) ; - (make-image-tweet String String Image) ; - (make-retweet String Tweet) ; INTERPRETATION: A tweet is either a message (make-tweet), ; a message and an image (make-image-tweet), or a retweet ; of another tweet (make-retweet). All tweets have authors. ; A Feed is a [List-of Tweet] ; INTERPREATION: A list of the Tweets in a user's feed. Without using the list functions (like map, filter, etc.), design the function count-tweets.v1, which accepts a Feed and returns a Number representing the total number of Tweets in the Feed. Note that a retweet has more than one Tweet in it. For exampleThere was a typo in this example; it is now fixed.
(check-expect (count-tweets.v1 (list (make-tweet "foo" "bar") (make-retweet "baz" (make-retweet "blah" (make-image-tweet "arg" "grr" empty-image))))) 4)
Exercise 2 Redesign the function count-tweets using any appropriate list functions (map, filter, etc.) Call this function count-tweets.v2. You may use any helper functions that you designed for the previous exercise when completing this one —
except, of course, for count-tweets.v1 itself!
Forum Exercises
Over the next two weeks you’ll be working on a large improvement to the Forum project: the ability to reply to posts, and to view a thread of a post and its replies. This is tricky, and involves changing your data definitions when communicating with the server...which might also involve changing your definitions for your world state as well. Examples of data and examples of function calls will be crucial here, so be meticulous and methodical.
Additionally, this week, you are getting to know your new partner’s code from their prior assignments. You will need to decide which portions of each other’s code to keep, which parts to merge, and which parts to revise. In the process, you’ll have a chance to discover how someone else approached the same problems you did, and improve your code along the way.
Before starting this assignment: Combine your prior homework with your partner’s, to produce one working program with the best parts of each of your prior code.
Exercise 3 – Code cleanup: Now that you have list abstractions and local definitions available, go back through your merged code, and rewrite as many functions as you can to use list abstractions. At a minimum, you should be able to simplify your functions for drawing posts and for searching for posts...