scranton.list
Interface RecursiveList

All Known Implementing Classes:
RecursiveListViaLinear1Ind

public interface RecursiveList

A Java interface that parallels lists as defined by John McCarthy in LISP, a list is either empty or it is an ordered pair (head, Tail) where "head" is the object in the list and "Tail" is a, possibly empty, list (sublist).

Specifications:
A RecursiveList is
  • empty, L=()
  • or L = (h, T), where h is an object called the head and T is a, possibly empty, RecursiveList, called the tail

Initial Value:
L = ()


Method Summary
 java.lang.Object headOf()
          Returns reference to the Object at the head of the list.
 void insert(RecursiveList L)
          Replaces the current list with a new list composed by concatenating the current list to the list in the parameter, this = L+this.
 boolean isEmpty()
          Returns true if the current list is empty.
 RecursiveList remove()
          If this = (h, T), remove the current list and replace it by its tail, this' = T, return (h, ()).
 RecursiveList tailOf()
          Returns reference to the tail of the current list.
 java.lang.String toString()
          Returns a string representation of the list.
 

Method Detail

isEmpty

public boolean isEmpty()
Returns true if the current list is empty.
Specifications:
Returns this==()?

Returns:
this==()

headOf

public java.lang.Object headOf()
Returns reference to the Object at the head of the list.
Specifications:
this!=()
this' = this = (h,T)
Returns h

Timing:
O(constant)

Returns:
Object Head of the list.
Throws:
assertion - error when this == ().

tailOf

public RecursiveList tailOf()
Returns reference to the tail of the current list.
Specifications:
this!=()
this' = this = (h,T)

Timing:
O(constant)

Returns:
RecursiveList Returns reference to the tail of the current list.
Throws:
Assertion - When this==().

insert

public void insert(RecursiveList L)
Replaces the current list with a new list composed by concatenating the current list to the list in the parameter, this = L+this.
Specifications:
this'= L + this

Parameters:
L - List that will be prepended to this.

remove

public RecursiveList remove()
If this = (h, T), remove the current list and replace it by its tail, this' = T, return (h, ()).
Specifications:
this!=()
this=(h,T)
this'=T
Return (h, ())

Timing:
O(constant)

Returns:
RecursiveList Returns the tail of the current list.
Throws:
Assertion - when this==().

toString

public java.lang.String toString()
Returns a string representation of the list. Returns the string representation, "[head \t tail]" or "[]" is the list is empty.

Returns:
RecursiveList empty list object from the implementing class