8.7 Placement 4
8.7.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”.
There is also a second part [Learning by Contributing] to this assignment. Please see below.
8.7.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.
8.7.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.
8.7.4 Reading
14.1
14.2
14.4
15.1
15.4
16.1
16.2
16.5
8.7.5 Task
Define the same functions as in Placement 3. However, you are not allowed to use explicit recursion; you must use one of the functions listed in Library in its stead. You are of course welcome to write helper functions.
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 received for Placement 3.
Note that unique is a bit challenging and it’s okay if you can’t complete it after you’ve spent a while trying.
8.7.6 Turnin
You will again turn in two files.
One file, named p4-code.rkt, contains the five functions required above (it can contain any other helper definitions you like as well). The functions must be named exactly as decribed and must take parameters exactly as described. (Note: Google Drive will automatically rename your file(s) to include your name. This is fine.)
In addition, make a copy of just the test cases for the
required functions—
Failure to follow any of these instructions may result in zero credit.
Upload your file here. You will need to be logged into the Google@Brown domain to upload.
8.7.7 Learning by Contributing
We have added another part to Placement 4’s task. It’s based on Contributing Student Pedagogy, which enhances learning. It will also help us gauge what you’ve struggled with, helping us improve future versions of this class.
Please do this task after you have completed and submitted your assignment. (It will not require any changes to the files you turned in.)
Write a small program (please pay attention to the format), intended for your fellow students. Don’t include a purpose statement or give it a meaningful name and certainly do not include any tests! For brevity, you can also leave out any data definitions already seen in class. For most programs, you can include just executable code and, if you think it helps, a contract.
For this part, you are welcome to run it in DrRacket to make sure it doesn’t contain syntax errors, etc. You can also use it to see whether it produces the output you expect, but even if it does not—
especially if it does not— please submit it! But please don’t paste in your homework solutions. Predict the output of programs written by your fellow students.
For this part, you should not run the program in DrRacket. However, you should make a copy of the program and, after you are done with all the programs you are assigned, run each of them to compare your predicted answer against the true answer. If you don’t understand why one of them produced the answer it did, ask us privately on Piazza.