Assignment 13
Due Date Monday 03/18 at 9pm
Purpose To practice iterative refinement and list-processing with built in abstractions.
You should submit a single .rkt file containing your responses to all exercises via the Handin Server. We accept NO email submissions. Failure to submit a .rkt file will result in a 0.
You are only allowed to use the language specified at the top of this page: failure to do so will result in a 0.
Your code MUST conform to the guidelines outlined in the style guide on the course website. The style guide will be updated as the semester progresses so please remember to read it before submitting each assignment.
You must follow all the steps of the design recipe when completing this assignment.
Please be sure to look at the feedback for assignment 11 before submitting, as we will be grading you more harshly on things we have warned you about before.
You must submit this assignment with your partner. Please make sure you can submit with your partner before 5pm on Monday or we cannot guarantee that you will be able to submit your homework before the deadline. If the course staff are unable to assist you after 5pm and this causes your homework to be late we will not grant an extension.
Sleeping Soundly - Part 3
Exercise 1 Revise your sheep game from part 2 according to the feedback you received.
Exercise 2 Update the game to use list abstractions wherever they are appropriate. Look for places where you made use of the list template in homework 10.
Anonymous Functions
Use lambda to complete the following exercises.
Exercise 3 Design the function two that takes a function f : [X -> X] as input and returns another function that applies f twice in a row. That is, two returns a function which first applies f to its input, then applies f again to the output of the first application (all within one function call). Be sure to provide check-expects for your function.
Exercise 4 Design the function three, similarly, that applies a function f three times in a row.
Exercise 5 Design the functions one and zero in a similar spirit to the functions you designed in the previous two exercises. Writing one is easy, but what about zero? What does it mean to apply a function to its argument zero times?
The functions zero, one, two, and three look curiously similar to numbers: all they do is repeat their input some number of times. Let’s call functions like these Repeaters:
; A Repeater is a function [[X -> X] -> [X -> X]] ; That, given a one-argument function f, outputs a ; function that will repeatedly apply f some specific number of times
Exercise 6 Design a function rep->nat which consumes a Repeater as input and produces the number of times it repeats its argument. Here are some tests:
(check-expect (rep->nat zero) 0) (check-expect (rep->nat one) 1) (check-expect (rep->nat two) 2) (check-expect (rep->nat three) 3) (check-expect (rep->nat (λ (f) (λ (x) ((three f) ((two f) x))))) 5) Hint: If you have a Repeater, all you can do is give it some inputs and see what it gives you back. So your task here is simply to devise some inputs that will force it to tell you which number it represents. You do not need to use lambda to complete this exercise.