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.


Field Summary
private  PLTerm Head
           
private  int INCREMENT
           
private  int START_CAPACITY
           
private  PLTerm Tail
           
 
Fields inherited from class CiaoJava.PLTerm
ATOM, AtomTable, currentVersion, fail, FLOAT, INTEGER, INTERPRETER_ERROR, INTERPRETER_SUCCESS, JAVA_OBJECT, LIST, MAX_READ_BUFFER, nil, PFX_ATOM, PFX_FLOAT, PFX_LIST_WITH_NIL_TAIL, PFX_LIST_WITH_NONIL_TAIL, PFX_LONG_INT, PFX_MULTI_REF_ATOM, PFX_MULTI_REF_STRUCT, PFX_MULTI_REF_VAR, PFX_SHORT_INT, PFX_SINGLE_REF_VAR, PFX_STRUCT, PFXC_ATOM, PFXC_FLOAT, PFXC_INTEGER, PFXC_LIST, PFXC_NIL, PFXC_STRING, PFXC_STRUCT, PFXC_VARIABLE, PROLOG_EXCEPTION, PROLOG_FAIL, PROLOG_QUERY_ID, PROLOG_SUCCESS, STRING, STRING_BUFFER_SIZE, STRUCTURE, success, Type, VarCounter, VARIABLE, VarNumber, VERSION_A, VERSION_C
 
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.
 void backtrack(PLTerm term)
           
 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(PLInterpreter i)
          Java representation of a PLList.
 int length()
          Returns the number of elements of this PLList.
protected  int numberOfCells()
          Returns the number of cells needed to represent this PLList in the Prolog heap.
protected  void setTail(PLList l)
          Sets the tail of a PLList object, removing the previous tail.
 java.lang.String toString()
          String representation of a Java PLList object.
 boolean unify(PLTerm term)
          Term unification.
 
Methods inherited from class CiaoJava.PLTerm
fastRead, fastWrite, genPrefix, genTerm, getChar, getFloat, getInt, getPrefix, getString, getTerm, isException, isList, isNil, isPrologFail, isPrologSuccess, isQueryId, isSolution, isString, isStructure, isVariable, launchGoal
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

Head

private PLTerm Head

Tail

private PLTerm Tail

START_CAPACITY

private final int START_CAPACITY

INCREMENT

private final int INCREMENT
Constructor Detail

PLList

public PLList(PLTerm h,
              PLTerm t)
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)
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)
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.
Returns:
The string representation of the Prolog list.
Overrides:
toString in class PLTerm

javaRepr

public java.lang.Object javaRepr(PLInterpreter i)
Java representation of a PLList. The Java representation of a Prolog list is an object array.
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.
Overrides:
javaRepr in class PLTerm

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.
Returns:
always false.
Overrides:
isRunnable in class PLTerm

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.

setTail

protected void setTail(PLList l)
Sets the tail of a PLList object, removing the previous tail. Important: this method does not conform Prolog list handling and must be used very carefully.
Parameters:
l - PLList object that represents the new tail.

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.
Parameters:
t - Prolog term to be compared to.
Returns:
true if this term is equal to the term received as argument; false otherwise.
Overrides:
equals in class PLTerm

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.
Returns:
a PLTerm object that is a full copy of this list. All the elements of this list are copied in turn.
Overrides:
copy in class PLTerm

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.

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

backtrack

public void backtrack(PLTerm term)
               throws PLException
Overrides:
backtrack in class PLTerm

length

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

numberOfCells

protected int numberOfCells()
Returns the number of cells needed to represent this PLList in the Prolog heap. Only used to build the fast_write representation in 'a' version.
Returns:
the number of cells needed.
Overrides:
numberOfCells in class PLTerm