8.1 Points and Rectangle ***
The purpose of this exercise is to strengthen your understanding of functions used as classes in Scheme.
First, play with the existing Point class defined on this page available from the on-line version of this material.
As an example, construct two points and add them together. Also, construct two lists of each four points, and add them together pair by pair.
Define a new method in the Point class called (move dx dy) , which displaces a point with dx units in the x direction and dy units in the y direction. We encourage you to make a functional solution in which move creates a new displaced point. After that you can make an imperative solution in which the state of the receiving point is changed.
Finally, define a new class, Rectangle , which aggregates two points to a representation of a rectangle. Define move and area methods in the new class.
As a practical remark to the 'class Point ' and the send primitive, be sure to define send before you define Point . (This is done to redefine an existing send procedure in MzScheme).
8.2 Color Point Extension ***
On this page we have introduced the class ColorPoint, which inherits from Color .
In the sample dialogue with a couple of color points we have identified the problem that the sum of two color points is not a color point. Why is it so?
You are now supposed to make a few changes in the classes Point and ColorPoint. In order to make it realistic for you to play with the classes, your starting point is supposed to be a pre-existing file, with all the useful stuff (available from the on-line version of this material).
When you experiment with points and color-points, use M-x run-laml-interactively from Emacs.
8.3 Representing HTML with objects in Scheme ****
This is an open exercise - maybe the start of a minor project.
In the original mirror of HTML in Scheme, the HTML mirror functions, return strings. In the current version, the mirror functions return an internal syntax tree representation of the web documents. With this, it is realistic to validate a document against a grammar while it is constructed. In this exercise we will experiment with an object representation of a web document. We will use the class and object representation which we have introduced in this lecture.
Construct a general class html-element which implement the general properties of a HTML element object. These include:
In addition, construct one or more examples of specific subclasses of html-element , such as html , head , or body. These subclasses should have methods to access particular, required constituents of an element instance, such as the head and the body of a HTML element, and title of a head element. Also, the concrete validation predicate must be redefined for each specific element.
Generated: Friday January 3, 2014, 09:49:34