Comp 212 Assignment #2
Recursive Immutable Structures and Visitors
Due 6:00 PM, Friday, February 07, 2003 - No Late Submission will be accepted
This homework exercise serves as a transition from functional programming to object-oriented programming. It is based on the immutable list framework discussed in lecture 08 and in lab 03.
Your task is to write algorithms on Each of the above problems should be done independently from each other. Consider the
following description of recursive immutable data structure that represents web pages.IList
as visitors
as specified in the following problems. The classes IList, IEmptyList, INEList,
EmptyList, NEList should be in a package named OOscheme.
You are free to add any private
and protected methods to your visitor classes to support your public operations.
You are also free to write helper visitors to support your main visitors.
You are not allowed to check for the type of any object, such as using instanceof
or add a method to check for the type, to perform any task. The
visitors should be in a package named OOscheme.visitor,
unless specified otherwise.
IList
with
matching parentheses as in Scheme. For example, ToString for the list
containing 1, 2 ,3, should return (1 2 3),
and ToString for the empty list should
return (). 3 pts
IList
that contains the first n elements of the host. Here
0 <= n, and the case n
equals 0 corresponds to the empty list. Decide how
to pass n to FirstNElements yourself.
5 pts
II. The Tangled Web
All programs in this exercise should be written in a purely functional style: no object fields should be modified once they have been initialized by a constructor.
As with all programs in this course, lack of good coding style (good style includes reasonable variable names, a comment preceding each method, consistent indentation) will result in a substantial loss of points. The code should be documented in javadoc style. The provided java files in the labs and lectures can serve as examples of coding style and documentation format that are acceptable to us.
The homework is due Friday, February 07, 2002 at 6:00 PM. It is to be submitted electronically. No late submission will be accepted. The electronic submission project name is "visitor". The complete homework set should contain the following: