CiaoJava
Class PLList

java.lang.Object
  |
  +--CiaoJava.PLTerm
        |
        +--CiaoJava.PLList

public class PLList
extends PLTerm

Java representation of a Prolog list. Contains a representation of a Prolog list using the same head/tail structure of the Prolog lists The last element of the list must be an empty list. The empty list must be referred as the PLTerm.nil static field, due to the serialization mechanism of Prolog terms, that represents the empty list as an atom, not a list.


Fields inherited from class CiaoJava.PLTerm
fail, nil, success
 
Constructor Summary
PLList(PLTerm[] list)
          Given a Java list, creates a Java PLList object containing the objects included in the Java list.
PLList(PLTerm h, PLTerm t)
          Given a head and a tail, creates a Java PLList object.
PLList(java.lang.String s)
          Given a Java string, creates a Java PLList object containing the characters included in the Java string.
 
Method Summary
 void add(PLTerm term)
          Adds a term at the tail of a PLList object.
 PLTerm copy()
          Makes a full copy of this PLList Prolog list object.
 boolean equals(PLTerm t)
          Compares the PLList object with the PLTerm given as argument.
 PLTerm getHead()
          Gets the head of a PLList object.
 PLTerm getTail()
          Gets the tail of a PLList object.
 boolean isRunnable()
          Execution test on Prolog objects.
 java.lang.Object javaRepr(CiaoJava.PLInterpreter i)
          Java representation of a PLList.
 int length()
          Returns the number of elements of this PLList.
 java.lang.String toString()
          String representation of a Java PLList object.
 boolean unify(PLTerm term)
          Term unification.
 
Methods inherited from class CiaoJava.PLTerm
isList, isNil, isString, isStructure, isVariable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PLList

public PLList(PLTerm h,
              PLTerm t)
       throws PLException
Given a head and a tail, creates a Java PLList object. The tail term must be nil or another PLList.
Parameters:
h - First element of the list. Can be any Prolog term.
t - Rest of the list. Must be nil (if the list contains just one element), or another PLList object.

PLList

public PLList(PLTerm[] list)
       throws PLException
Given a Java list, creates a Java PLList object containing the objects included in the Java list. Is important to realize that the array argument must contain at least one element. An empty list is implemented in the Java representation as an atom with name "[]".
Parameters:
list - Java list that contains the elements that must be included in the Prolog list.

PLList

public PLList(java.lang.String s)
       throws PLException
Given a Java string, creates a Java PLList object containing the characters included in the Java string. Is important to realize that the string argument must contain at least one character. An empty list is implemented in the Java representation as an atom with name "[]".
Parameters:
s - Java string that contains the characters that must be included in the Prolog list as elements.
Method Detail

toString

public java.lang.String toString()
String representation of a Java PLList object.
Overrides:
toString in class PLTerm
Returns:
The string representation of the Prolog list.

javaRepr

public java.lang.Object javaRepr(CiaoJava.PLInterpreter i)
Java representation of a PLList. The Java representation of a Prolog list is an object array.
Overrides:
javaRepr in class PLTerm
Parameters:
i - PLInterpreter object used to do the interpretation. Included here only for compatibility purposes with the PLTerm abstract class.
Returns:
a Java object that represents the Prolog list. This Java representation is built by an Object array.

isRunnable

public boolean isRunnable()
Execution test on Prolog objects. Returns true if the related Prolog term can be evaluated. Implements the abstract method declared in the PLTerm class.
Overrides:
isRunnable in class PLTerm
Returns:
always false.

getHead

public PLTerm getHead()
Gets the head of a PLList object.
Returns:
the first element of the Prolog list.

getTail

public PLTerm getTail()
Gets the tail of a PLList object. The object returned may be nil or another list.
Returns:
the Prolog list result of removing the first element of this list.

add

public void add(PLTerm term)
Adds a term at the tail of a PLList object.
Parameters:
term - Prolog term to be added at the end of this list.

equals

public boolean equals(PLTerm t)
Compares the PLList object with the PLTerm given as argument. Implementation of the method inherited from PLTerm.
Overrides:
equals in class PLTerm
Parameters:
t - Prolog term to be compared to.
Returns:
true if this term is equal to the term received as argument; false otherwise.

copy

public PLTerm copy()
Makes a full copy of this PLList Prolog list object. Recursively clones the elements of this term, in order to return a separated copy of all the elements included in this list.
Overrides:
copy in class PLTerm
Returns:
a PLTerm object that is a full copy of this list. All the elements of this list are copied in turn.

unify

public boolean unify(PLTerm term)
Term unification. Unifies this Prolog list with the term received as argument. This method overrides the one inherited from PLTerm.

Important: The unification is 'two sided': the variables found in the term received as argument could be bound in order to unify the complete terms. In the same way, the variables found in this list could be bound to unify both terms.

Overrides:
unify in class PLTerm
Parameters:
term - Term to unify with.
Returns:
true if the unification is successful; false otherwise.

length

public int length()
Returns the number of elements of this PLList.
Returns:
The number of elements of this Prolog list.