CMPS 240 Summer 2019
Prog. Assg. #5: Recursive List Utilities

Background

In the late 1950's, John McCarthy of MIT developed LISP ("LISt Processing"), the first functional programming language. In such languages, the standard way to perform iteration is via recursion, as opposed to loops. As suggested in its name, lists play a central role in LISP. In particular, lists are viewed as being recursive in structure, which makes it natural to process them using recursive code. Specifically, a list can be either

Suppose that we use [] to denote the empty list and [x,y] to denote the (nonempty) list whose head is x and whose tail is y. Then, as an example, the 4-element list containing dog, cat, elk, and cow (in that order) would be viewed as having the structure suggested by

[dog, [cat, [elk, [cow, []]]]]

That is, this list's head is dog and its tail is [cat, [elk, [cow, []]]]

For reasons having to do with the names of the registers in the computer on which the language was first implemented, in LISP the head of a list is referred to as its CAR and the tail as its CDR (pronounced "cudder"). In our work, we will use the more meaningful words "head" and "tail". However, we will retain "cons", which is LISP's name for the function that constructs a list from an element x and a list y, to form the list [x,y].

Task

Here are the Java source code files that you will need:

In case you want to see the methods in RecursiveListUtils "in action", you can make use of RecListUtilsTester.