Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Here the host structure is IntList and its concrete subclasses, and the visitor is any extrinsic operation to be performed on the IntList host. Instead of adding methods to IntList to perform additional operations, we write visitors.

...

NOTE

...

: Visitors that take no arguments should be written as Singletons.
We now translate code we wrote using the interpreter pattern on IntList in previous labs using visitors instead.

...

  1. Write a visitor called Length to compute the length of an IntList. #*
    1. Write a non-tail recursive version (using direct recursion).
    2. Write a tail-recursive version using a helper visitor (in place of a helper method).
  2. 2 Write a visitor called ProdNums that returns the product of the number in the list, using a tail recursive helper visitor. 3
  3. Write a visitor called Reverse that reverses the list using a tail-recursive helper visitor.
  4. 4 Write a visitor called ListString that uses as tail recursive visitor as done in the method listString.
  5. 5 Write a visitor called MakePalindrome that returns a list consisting of the input list and its mirror around the last element, using a (non tail-recursive) helper with an accumulator. For example, (1, 2, 3).accept(MakePalindrome.ONLY) returns the list (1, 2, 3, 2, 1) .

...

Access Permissions: (Please don't edit)

...