Lab 7
Implement a small class hierarchy modeling objects as closures in ZHRL3 . 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.
In other words, what you’re really working on here is the expected result for a whole bunch of excellent test cases for Assignment 5, in a setting where you’re encouraged to collaborate with others in the class. The goal here is to simplify Assignment 5 dramatically!
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 ZHRL3 number. If binary operators are easier, you can just include an ignored second argument.
Implement a Point in ZHRL, 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 ZHRL .
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 rec 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 ZHRL3, 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.