We are providing you with starter code, CC8-template.scm. You should download this file and upload the given code to a new .scm file named last-CC.scm.
You are required to document every procedure that you write using the documentation style of our course. Tests are optional, but likely helpful in determining if your code is working as desired.
At the top of your file, make sure to include your name, and any acknowledgements according to our collaboration policy. Now is a great time to review those collaboration policies.
Document and write a recursive procedure, (my-vector-filter vec pred?),
that creates a new vector which contains only the elements of vec for which
pred? holds. The elements should appear in the same order that they do in
vec.
In writing this procedure, you may create exactly one new vector. Hence,
you will not find it productive to use vector-append. In addition,
you may not create any lists. Hence, you will not find it productive
to use list->vector or vector->list.
Hint: You may have to iterate the vector twice, once to determine the size of the result vector and once to fill it in. A helper procedure will be useful for that.
> (my-vector-filter (vector 1 2 3) number?)
'#(1 2 3)
> (my-vector-filter (vector 1 2 3 "a" #\b #t) number?)
'#(1 2 3)
> (my-vector-filter (vector 1 'a 2 'v 3 'c) number?)
'#(1 2 3)
> (my-vector-filter (vector 1 "you" 2 "can" 3 "do" "it") string?)
'#("you" "can" "do" "it")
Suppose that we have a table of speeches, each entry of which represents one speech and contains two strings, which correspond to the speaker name and the words that they said.
(define some-speeches
(list (list "Joe" "My name is Joe")
(list "Jane" "I heard that Abraham Lincoln once said that ...")
(list "Joe" "My name is still Joe")
(list "Jae" "I am not inclined to speak at length, nor on matters ...")
(list "Joe" "It's still Joe")
(list "Jo" "I am often mistaken for another person. Let me explain ...")
(list "Joe" "I'm not Jo")
...))
a. Write a procedure, (visualize-speeches
speeches) that takes a list of that form as input and makes
a scatterplot in which the x-axis represents the number of words in a
speech and the y-axis represents the average word length in the speech.
Each point in the scatterplot corresponds to one of the speeches.
You may choose to treat words as “anything separated by spaces”, and therefore get the words by splitting the speech at the space character.
Your solution should assume that the table some-speeches already
exists in your file (you should not use with-file)
Make sure your plot has a title and axes labels that are informative.
b. Of course, our scatterplot would be much more useful if we could
identify the speakers. Write a procedure,
(visualize-speeches-prime speeches speakers),
that behaves much like visualize-speeches except that it also takes
a list of speakers of exactly length two. You should plot the two speakers with distinct colors, and label them with the speakers name.
You may assume that every speech in speeches is given by one of
the named values in speakers.
c. It is not clear that scatterplots are the best way to visualize this
information. Write a procedure, (speech-histogram
speeches), that creates a histogram of the ratio of speech
length to average word length. Your histogram should have one bar per
speech and have the speaker name under the bar.
Submit last-CC.scm to Gradescope.
In grading your submission, we will look for the following at each level. Note that if a criteria does not pass a lower level, we will likely not check for criteria at the higher levels. We may also identify other characteristics that move your work between levels.
You should read through the rubric and verify that your submission meets the rubric.
Submissions that lack any of these characteristics will get an N.
[] Includes the specified file (correctly named).
[] Includes an appropriate header on the file that indicates the course, author, acknowledgements, etc.
[] Acknowledges appropriately.
[] Code runs in scamper.
Submissions that lack any of these characteristics but have all of the prior characteristics will get an R.
[] Code is well-formatted with appropriate names and indentation.
[] Code submission is organized with comments to indicate the start of new problems.
[] Solution for problem 1 does not use lists, `vector-filter`, or `vector-append`
[] All of our tests pass for Problem 1.
[] Problem 2 produces three figures with labels that make sense.
[] Documentation in the 151 style is included for all code, and contains correct information.
Submissions that lack any of these characteristics but have all of the prior characteristics will get an M.
[] All code is exceptionally organized and easy to read, through the use of comments (to explain the purpose of different pieces of the code), decomposition, and highly intuitive naming choices.
[] Problem 1 includes a wide variety of tests which cover edge cases beyond those presented in the assignment.
[] Submission demonstrates testing problem 2 on multiple datasets.
[] Solutions in problem 2 produce appropriate figures with our test datasets