Comp 212 Homework 2
Visitor

Due Sept. 22, 2000 11:59 PM.

This homework exercise serves as a drill on applying the visitor pattern to the Scheme list structure.  It is based on homework 01 and lab 03.

Your task is to write algorithms on lists as visitors as specified in the following problems.  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 AListFW, such as using instanceof or add a method to check for the type, to perform any task.  The classes AListFW, EmptyListFW, NEListFW, and ListFWFactory should be in a package named scheme2 as shown in lab 03.   The visitors should be in the package scheme2.visitor.

  1. Write a visitor called ToString to print AListFW with matching parentheses as in Scheme.  The empty list should prints as ().  Add the method toString() to AListFW to call ToString to do the job.  This method should not be abstract.
  2. Write a visitor called Reverse to compute and return the host in reverse order.
  3. Write a visitor called MakeClone to compute and return a copy of the host.
  4. Write a visitor called GetNth to compute and return the n-th elements of the host.  Here 0 <= n, and the case n equals 0 corresponds to the first element of the list.  Decide how to pass n to GetNth yourself.
  5. Write a visitor called LastElement to find and return the last element of the host.  Do this without using the length of the host.
  6. Write a visitor called FirstNElements to compute and return an AListFW 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.
  7. Write a visitor called  ConcatWith to concatenate the host with the input parameter and return the resulting AListFW.

Each of the above problems should be done independently from each other.  For each of the above problems, be sure to add test cases which cover all reasonable cases.  As with all programs in this course, lack of good coding style (good style includes reasonable variable names, a header before each non-overridden function, reasonable indentation) will result in a substantial loss of points.  The code should be documented in javadoc style. 

Submission

The homework is due Friday Sept. 22, 2000 11:59 PM.  It is to be submitted electronically.  Your labbies will give you specific submission instructions in the upcoming lab tutorial.  No late submission will be accepted.  The complete homework set should contain the following:


dxnguyen@cs.rice.edu         Please let us know of any broken links             Revised Sept. 18, 2000