Week 5 Set c
Due Date Fri at 9:00pm (Week 5)
Purpose The purpose of this problem set is to get to know local and to get a first taste of refactoring, that is, transforming code without changing its behavior with the goal of improving its readability and other attributes.
Finger Exercises
Exercise 1 Here is the header material for a function that computes the Manhattan distance of a Posn to the origin:
; Posn -> Number ; compute the Manhattan distance of p to orgin (define (manhattan-distance p) 0) Develop five test cases. Then compare and contrast the test cases in the same way we compared and contrasted similar functions in lecture. Can you develop the function body from this analysis?
Exercise 2 Design the function largest and smallest. Both consume a list of Posns and produce the one whose x coordinate is largest or smallest, respectively.
Now compare the two functions and abstract over them.
Graded Exercises
Exercise 3 Your software architect has inspected your code and noticed that you didn’t seem to know about local definitions. Apparently, your code contains repeated expressions within the same function, exhibits "right shift"This is not a political attribute, which would be dangerous on a college campus., and comes with helper functions that are useful to only one handler function.
Your task is to use local to "prettify" your code. In the real world, this is called refactoring. Many companies encourage such refactorings, and many IDEs support some of them with mouse clicks and key strokes. Since you are a novice programmer, you need to do these refactorings by hand to understand the idea.
Don’t forget to re-run the test suites as you refactor. Doing so will catch any mistakes you introduce.