ix.util.lisp
Class LList

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.AbstractSequentialList
                    |
                    +--ix.util.lisp.LList
All Implemented Interfaces:
java.util.Collection, LispObject, java.util.List, java.io.Serializable
Direct Known Subclasses:
Cons, Null

public abstract class LList
extends java.util.AbstractSequentialList
implements LispObject, java.io.Serializable

Lisp-style lists.

An LList can be treated as a Collection that is sequential, fixed-size, and modifiable. However, the linked structure is visible; and that allows them to be used in ways that typical Java collections cannot. Two LLists can share structure by having a common tail. Moreover, an LList is not constructed by creating an empty LList and then adding elements; instead it is typically made from a single element, which becomes the first element of the LList, plus an existing LList that contains the rest. This supports a different style of programming closer to what is used in functional languages, Lisp, and Prolog.

For a Collection based on LLists that works in the more usual Java manner, use an LListCollector.

The class structure is like that in Common Lisp -- there is an abstract class List with two subclasses, Cons and Null -- but only proper lists are allowed. The car of a Cons can be any Object, but the cdr must be a List.

The empty list is the value of Lisp.NIL and is the only instance of the class Null.

An important goal was that all lists, including the empty list, could be enumerated. That's one reason for having a List subclass for the empty list, rather than just using a unique Object or null. The subclass also allows a number of other methods to be defined for all lists. (A plausible alternative, however, would be to have just one class, LList, and have the empty list be a unique instance of that class.)

See Also:
LListCollector, Lisp, Cons, Null, Serialized Form

Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
LList()
           
 
Method Summary
abstract  LList append(LList tail)
           
abstract  java.lang.Object car()
           
abstract  LList cdr()
           
 java.lang.Object clone()
           
 LList delete(java.lang.Object e)
           
 LList drop(int n)
           
abstract  java.lang.Object elementAt(int i)
           
abstract  java.util.Enumeration elements()
           
abstract  boolean equal(LList list)
           
abstract  boolean find(java.lang.Object a)
           
 LList flatmap(Function1 f)
           
 java.lang.Object get(java.lang.Object propname)
           
 LList insert(java.lang.Object e, Predicate2 lessp)
           
 LList intersect(LList set)
           
 boolean isEmpty()
           
abstract  boolean isNull()
           
 java.util.Iterator iterator()
          Returns an interator over the elements of the list.
 Cons lastCons()
           
 int lastIndexOf(java.lang.Object o)
           
abstract  int length()
           
 java.util.ListIterator listIterator(int index)
           
 LList mapc(Function1 f)
           
 LList mapcar(Function1 f)
           
 LList permute()
           
 LList replaceAll(java.lang.Object old, java.lang.Object neu)
           
 LList reverse()
           
 int size()
           
 LList take(int n)
           
 void walkTree(Function1 f)
           
 LList without(java.lang.Object e)
           
 
Methods inherited from class java.util.AbstractSequentialList
add, addAll, get, remove, set
 
Methods inherited from class java.util.AbstractList
add, clear, equals, hashCode, indexOf, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

LList

public LList()
Method Detail

listIterator

public java.util.ListIterator listIterator(int index)
Overrides:
listIterator in class java.util.AbstractSequentialList

size

public int size()
Overrides:
size in class java.util.AbstractCollection

iterator

public java.util.Iterator iterator()
Returns an interator over the elements of the list. Note that the result is a plain Iterator, not a ListIterator, because Iterators require less state and can be implemented more efficiently.
Overrides:
iterator in class java.util.AbstractSequentialList

isEmpty

public boolean isEmpty()
Overrides:
isEmpty in class java.util.AbstractCollection

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Overrides:
lastIndexOf in class java.util.AbstractList

isNull

public abstract boolean isNull()

car

public abstract java.lang.Object car()

cdr

public abstract LList cdr()

length

public abstract int length()

elementAt

public abstract java.lang.Object elementAt(int i)

elements

public abstract java.util.Enumeration elements()

equal

public abstract boolean equal(LList list)

find

public abstract boolean find(java.lang.Object a)

append

public abstract LList append(LList tail)

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

reverse

public LList reverse()

get

public java.lang.Object get(java.lang.Object propname)

lastCons

public Cons lastCons()

take

public LList take(int n)

drop

public LList drop(int n)

without

public LList without(java.lang.Object e)

delete

public LList delete(java.lang.Object e)

insert

public LList insert(java.lang.Object e,
                    Predicate2 lessp)

replaceAll

public LList replaceAll(java.lang.Object old,
                        java.lang.Object neu)

mapc

public LList mapc(Function1 f)

mapcar

public LList mapcar(Function1 f)

flatmap

public LList flatmap(Function1 f)

walkTree

public void walkTree(Function1 f)

intersect

public LList intersect(LList set)

permute

public LList permute()