...
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.
...
- Write a visitor called Length to compute the length of an IntList. #*
- Write a non-tail recursive version (using direct recursion).
- Write a tail-recursive version using a helper visitor (in place of a helper method).
- 2 Write a visitor called
ProdNums
that returns the product of the number in the list, using a tail recursive helper visitor. 3 - Write a visitor called
Reverse
that reverses the list using a tail-recursive helper visitor. - 4 Write a visitor called
ListString
that uses as tail recursive visitor as done in the method listString. - 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)
...