Lab 1000
THIS LAB IS OPTIONAL AND UNSCORED.
Q: So why are we posting it? A: Because making it a lab means that you’re free to discuss solutions to these problems with your friends and classmates; since these solutions are the basis for important test cases for your Program 5, this should make it easier to complete Program 5. If not, you’re welcome to ignore it completely.
Implement a small class hierarchy modeling objects as closures in ZIBR3 . 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.
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.
(Only required for interp:) Add a unary number? operator, that accepts a value and returns true when the argument is a ZIBR3 number. If binary operators are easier, you can just include an ignored second argument.
Implement a Point in ZIBR, 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 ZIBR .
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.
Develop a interp method written in ZIBR3, 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.