Re-read the adages page. Choose one (or several closely-related) adages, or one longer article, that mean more to you than they did at the beginning of the term.
Write an essay of one to five well-structured paragraphs on what this adage really means in practice. Do you agree or disagree? Support your claims with specific examples from your experience this semester.
You may also want to comment on your experience of Pair Programming: how well did it work, what were the advantages and disadvantages, what would make it work better, etc.?
Develop a function named add-up-to
which takes in a natural number and returns the sum of all the natural
numbers up to and including it.
Example:
(check-expect (add-up-to 3) 6) (check-expect (add-up-to 5) 15) (check-expect (add-up-to 10) 55)Note: there is a formula for this, but I want you to do it recursively, using only addition (no multiplication or division).
Develop a function named
dot-grid
that takes two natural numbers width
and height
, and produces a rectangular grid of circles with
width
columns and height
rows.
Example:
Develop a function randoms
that takes two natural numbers how-many
and limit
and
produces a list of how-many
numbers, each chosen randomly
from 0 up to limit
.
Example:
(randoms 10 15) (list 11 7 5 3 14 2 14 5 13 10)
Develop a function table-of-squares
which takes in a natural number and returns a list of
posn
s representing a table of numbers and
their squares up to the given number.
Example:
(check-expect (table-of-squares 4) (list (make-posn 4 16) (make-posn 3 9) (make-posn 2 4) (make-posn 1 1) (make-posn 0 0))Note: I've put these in descending order because it's easier to write the function that way. For extra credit, produce the table in increasing order instead.
For these problems, you'll need to be in DrScheme's Intermediate language
Develop a function remove-if
which takes in a list of X's (for any data type X), and a
function from X to boolean, and returns a list of X's containing only
the ones for which the function is false.
Develop a function
fire-over-100K
that takes in a list of employees (see
worked exercises
16.2.1 and 16.4.1)
and returns a list of the employees who earn under $100,000.
Hint: you should be able to do this in one or two
lines by re-using previously-defined functions.
Develop a function
give-10%-raises
that takes in a list of employees and
returns a list of the same employees, each earning 10% more than
before.
Hint: Use do-to-each
on a locally-defined
function that operates on a single employee.
Develop a function remove-over
which takes in a number limit
and a list of numbers,
and returns the list of the numbers less than or equal to limit
.
Hint: use remove-if
on a
locally-defined function that operates on a single number.
Choose one of the animations 16.8.4, 16.8.5,
16.8.6, and modify it so that it works with an
arbitrary number of dots, all moving simultaneously.
Every time the user presses the + key, an
additional dot should be added, with random location and velocity;
every time the user presses the - key, the most recently-added dot
should be removed.
Hint: change your model
from whatever struct it was to a list of structs, and look
for opportunities to use do-to-each
on this list.
Develop a function do-twice
that
takes in a function with contract "X -> X", and returns a
function with the same contract which applies the given function
twice. For example,
(define add2 (do-twice add1)) (check-expect (add2 3) 5)What does
(do-twice sqr)
do?
Generalize this to a function iterate
that takes a natural number and a function with contract "X -> X",
and returns a function with the same contract which applies
the given function the specified number of times. For example,
(iterate 2 f)
should be equivalent to (do-twice f)
, and
(define add5 (iterate 5 add1)) (check-expect (add5 3) 8)What does
(iterate 3 sqr)
do?
What about (iterate 5 sqr)
?
(iterate 3 (iterate 3 sqr))
?
(iterate 3 do-twice)
?
For these problems, you'll need to be in DrScheme's Advanced language.
Develop a function named next
that
takes no arguments, but each time you call it, it returns how many
times it has been called. Example:
> (next) 1 > (next) 2 > (next) 3
Develop a function named next-color
that takes no arguments, but each time you call it, it returns the next
element in the list (list "red" "orange" "yellow" "green" "blue"
"violet")
. If you call it more than six times, it returns
false
.
Develop a function named
make-lister
that takes in a list, and returns a function
like next-color
: it takes no arguments, but each time you
call it, it returns the next element in the list that was given to
make-lister
. If you run out of list elements, it returns
false
. Example:
> (define next-bird (make-lister (list "robin" "bluejay" "crow"))) > (next-bird) "robin" > (next-bird) "bluejay" > (next-bird) "crow" > (next-bird) false
The essay should be written individually and turned in with one name at the top. The programming problems should (ideally) be written by teams of two students, using Pair Programming.
Also turn in a log of how many errors of different kinds you encountered in the assignment, with brief comments describing each one ("mismatched parentheses" is self-explanatory, but more complex errors might need more description). Note that "errors" means not only error messages from DrScheme, but also wrong answers. You may do this using the PSP forms, or simply by keeping track in a text file or on paper and turning it in.
Error log: /30
(I'm not grading on how many or how few errors you encountered,
only on whether you recorded them correctly.)
I sha'n't actually grade all the problems; consider the others "practice". For each function I grade, see the table below, which has columns for each step in the design recipe. You won't turn in a separate skeleton, inventory, and definition, but rather write a skeleton, then add an inventory, then add a body to turn it into a complete definition. However, if you don't get the definition working, comment it out and you'll still get partial credit for a correct skeleton and/or inventory.
Contract | Examples | Skeleton | Inventory | Definition | Test results | Working animation (if applicable) |
---|---|---|---|---|---|---|
/5 | /5 | /5 | /5 | /10 | /5 | /10 |
Following directions | /10 |
Writing contracts from word problems | /10 |
Choosing examples | /10 |
Choosing names | /10 |
Coding | /10 |
Code re-use and function composition | /10 |