On this page:
4.1 Goal
4.2 Plagiarism
4.3 Language
4.4 Library
4.5 Reading
4.6 Programming
4.7 Turnin

4 Placement 4🔗

4.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”.

4.2 Plagiarism🔗

This assignment has become notorious for plagiarism. Every year we have found a significant number of students (up to 20%) have cheated on at least one of the problems. In the past we gave students another chance, but this has gotten tiresome, especially given the reason provided.

The standard argument we have heard is, “I cheated because the problem was hard”. This is a terrible argument. The problems are here to both prepare you for 0190 and make sure that it’s the right course for you. If you struggle here, you will struggle there also (perhaps much more!). How do you plan to handle that? Do you intend to cheat throughout the semester as well?

If we have good reason to believe you have plagiarized (which includes the use of ChatGPT-like toolsYou should anyway be careful about using ChatGPT-like tools: recent research shows that it both hurts learning and gives you an inflated sense of confidence.), we will refer you to the Academic Code committee, which will very likely sanction you. You will also not be admitted to 0190. So you will end up with a sanction on a course you didn’t take, couldn’t take, and that you didn’t need to take. What a way, especially for those of you starting college, to begin your academic career!

So please do the work honestly and turn in what you are able to do.

4.3 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.

4.4 Library🔗

You will not need more than the following higher-order functions:
  • 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).

4.5 Reading🔗

You will read from Part 3 of HtDP 2/e, specifically
  • 14.1

  • 14.2

  • 14.4

  • 15.1

  • 15.4

  • 16.1

  • 16.2

  • 16.5

You can read the rest if you feel the need as you’re doing the assignment.

4.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. That’s still recursion; it’s called mutual recursion. 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.

Three of the functions are repeated from Placement 3:
  • external-senders

  • unique

  • fix-shelves

There are four new problem as well:

  • 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.

4.7 Turnin🔗

You will have two submission drops on Gradescope: one each for programs and tests.

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.