Lab 7
Implement a small class hierarchy modeling objects as closures in PHYM 3/4. The idea of this lab is to help you to understand the desugaring operation for objects by writing things down in the *un*-sugared form. That is, the forms you write for this lab will not use the syntactic sugar that you add for assignment 5.
Start with your solution to assignment 3 OR 4.
Add string values to your assignment.
Add an expt binary operator, that accepts numbers a and b and computes a raised to the bth power. To make this easy, use the function of the same name from racket.
Add a unary number? operator, that accepts a value and returns true when the argument is a PHYM4 number.
Implement a Point in PHYM, as we’ve been doing in class. Include getter methods, and a "distance" function that accepts another point and returns the distance between this point and another point. Make sure your distance function works by writing tests in PHYM .
Implement a Triangle class , that includes three points. Include a "perimiter" method that computes the perimiter of the triangle, using the Point class. As before, make sure to write test cases.
Implement a Cons class, that represents a pair, including first and rest fields. Implement an Empty class, with no fields. Create examples of lists of numbers.
Add getters called first and rest to the Cons class. Develop the length method for Cons and Empty, that computes the length of a list.
Starting here, you’ll need a working recC form.
Develop the doublemap method for Cons and Empty, that can be called on a list of numbers and returns a new list where every number is doubled. In order to make this work, you’ll need to make the constructor recursive, using the trick described in chapter 9 of the book.
Add strings to your PHYM4 language, and extend equality to handle strings (two strings are equal if they contain the same sequence of characters).
Develop a interp method in PHYM4, that accepts s-expression-like terms formed using numbers, strings, Cons, and Empty, and returns the number the term evaluates to. You should include addition, subtraction, multiplication and division in your mini-language. Note that there’s no need to separate parsing from evaluation in the mini-language.