9 Placement 4
9.1 Goal
Functional programmers don’t actually spend all day writing recursive functions over lists. Rather, they use so-called “higher-order” functions, which are functions that consume other functions, to do that kind of work. That is, in functional programming, a loop is just a function, and different kinds of loops correspond to different kinds of higher-order functions. In this assignment you will learn about some of these “looping functions”.
9.2 Language
For the following assignment, you must use Racket’s Intermediate Student with lambda language. Go to the Language menu, select Choose Language, and pick the language from the Teaching Languages section.
9.3 Library
map
filter
foldl
foldr
andmap
ormap
You may also use any library function you were permitted to use on prior assignments, particularly in Placement 3.
Note that you cannot use reverse unless you implement it yourself (following the rules below).
9.4 Reading
14.1
14.2
14.4
15.1
15.4
16.1
16.2
16.5
9.5 Planning
Building on recent research in computing education, we are asking you to plan your solutions before you code them. The description of the planning component is given in this document. Please read it carefully and follow the instructions there.
9.6 Programming
You will define the following functions. In doing so, you are not allowed to use recursion (where a function calls itself) directly;Don’t try to be clever about this, e.g., having A call B and then B call A. you must use one of the functions listed in Library in its stead. You are of course welcome to write helper functions (that follow the same rule).
For the programming part, you are welcome to reuse anything appropriate that you wish from your Placement 3 submission, e.g., purpose statements and tests. You do not need to write templates.
We do expect you to do a thorough job on testing, building on the feedback you receive for Placement 3.
Note: This assignment has become notorious for plagiarism. Every year we have found a significant number of students have cheated on at least one of the problems. This has gotten tiresome. From this year onward, if you are found to have plagiarised, we will refer you to the Academic Code committee, and you may very well be sanctioned. (You will also not be admitted to 0190.) The argument “I cheated because the problem was hard” does not hold water: the problems are here to set you up for 0190. Do you intend to cheat throughout the semester as well? So please do the work honestly and turn in what you are able to do.
external-senders
unique
fix-shelves
elim-contains-char :: Char List-of-strings -> List-of-strings
Consumes a list of strings and produces a list of the same strings, in the same order, excluding those strings that contain the given character.
l33t :: List-of-strings -> List-of-strings
Consumes a list of strings (think of them as “words”) and produces a list of the same strings, in the same order, but where some of the letters have been replaced by characters that stand for numbers. Specifically, it turns #\A and #\a into #\4,Note that #\4 is a character, whereas 4 is a number. You can’t do arithmetic on the former or put the latter in a string. #\E and #\e into #\3, #\I and #\i into #\1, and #\O and #\o into #\0.
Note: The first letter of the function name we are asking for is the letter ‘l’ (Lima), not the number ‘1’ (One). It’s pronounced “leet” and is favored in basements worldwide. If you don’t follow our spelling, our grading software will not recognize your function, so you won’t get any credit!
is-palindrome :: String -> Boolean
A palindrome is a string with the same letters in each of forward and reverse order (ignoring capitalization). Design a program called is-palindrome that consumes a string and determines whether the string with all spaces and punctuation removed is a palindrome. Treat all non-alphanumeric characters as punctuation. The functions char-alphabetic? and char-numeric? may be useful.
viable-fish :: List-of-Fish, List-of-String -> List-of-Fish
There are strict rules about fishing in the United States. Catching and keeping a fish that is below a certain size can result in a hefty fine.
However, these rules don’t apply to any fish designated as an “invasive species”. In fact, in many locations, releasing these fish back into the wild carries its own fine.
A fishing boat skipper knows that they must follow the above rules for which fish to release, and wants to keep track of which fish are not subject to the above rules . At every point in time on the trip, they want to be able to determine which non-invasive fish in their catch are above the minimum size restriction (8 inches, in that state).
Fish data are presented with the following contract:;; species :: String
;; length-in-inches :: Number
(define-struct fish (species length-in-inches))
Design the function viable-fish, which takes in a list of caught fish currently in the boat and a list of names of invasive species (represented as strings), and returns a list, in the same order as the input, of the non-invasive fish that are larger than 8 inches.
9.7 Turnin
You will have three submission drops on Gradescope: one each for plans, programs, and tests.
Please name the plan file p4-plan.xml.
Please name the program file p4-code.rkt.
For the test files, please use the following names:
Problem |
| Filename for Tests |
external-senders |
| p4-es.rkt |
unique |
| p4-unique.rkt |
fix-shelves |
| p4-fs.rkt |
elim-contains-char |
| p4-ecc.rkt |
l33t |
| p4-lt.rkt |
is-palindrome |
| p4-ip.rkt |
viable-fish |
| p4-vf.rkt |
Please remind yourself of the instructions from Placement 3 on the contents of these files.
Failure to follow any of these instructions may result in zero credit.