Prolog Cafe v1.2

jp.ac.kobe_u.cs.prolog.lang
Class ListTerm

java.lang.Object
  extended by jp.ac.kobe_u.cs.prolog.lang.Term
      extended by jp.ac.kobe_u.cs.prolog.lang.ListTerm
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Term>

public class ListTerm
extends Term

List.
The class ListTerm represents a list structure.

  % [1,2]
  Term Nil = SymbolTerm.makeSymbol("[]");
  Term  n1 = IntegerTerm(1);
  Term  n2 = IntegerTerm(2);
  Term   t = new ListTerm(n1, new ListTerm(n2, Nil));
  
  Term car = ((ListTerm)t).car();
  Term cdr = ((ListTerm)t).cdr();
 
Here is sample program for creating a list from 1 to n.
 public static Term makeList(int n) {
   Term t = SymbolTerm.makeSymbol("[]");
   for (int i=n; i>0; i--) {
     t = new ListTerm(new IntegerTerm(i), t);
   }
   return t;
 }
 

See Also:
Serialized Form

Field Summary
protected  Term car
          Holds the first element of this ListTerm.
protected  Term cdr
          Holds the list consisting of all the rest of the elements of this ListTerm but the first one.
protected static SymbolTerm SYM_DOT
          A functor '.' /2.
 
Fields inherited from class jp.ac.kobe_u.cs.prolog.lang.Term
AFTER, BEFORE, EQUAL
 
Constructor Summary
ListTerm(Term _car, Term _cdr)
          Constructs a new Prolog list structure such that _car is the first element of this list, and _cdr is the list consisting of all the rest of the elements of this list but the first one.
 
Method Summary
 Term car()
          Returns the value of car.
 Term cdr()
          Returns the value of cdr.
 int compareTo(Term anotherTerm)
          Compares two terms in Prolog standard order of terms.
 boolean convertible(java.lang.Class type)
          Check whether this object is convertible with the given Java class type.
protected  Term copy(Prolog engine)
          Returns a copy of this object.
 boolean equals(java.lang.Object obj)
          Checks term equality of two terms.
 int hashCode()
           
 boolean isGround()
          Check whether this term is a ground term.
 int length()
          Returns the length of this ListTerm.
 void setCar(Term t)
          Sets the value to car.
 void setCdr(Term t)
          Sets the value to cdr.
 java.lang.Object toJava()
          Returns a java.util.Vector corresponds to this ListTerm according to Prolog Cafe interoperability with Java.
 java.lang.String toQuotedString()
          Returns a quoted string representation of this term.
 java.lang.String toString()
          Returns a string representation of this ListTerm.
 boolean unify(Term t, Trail trail)
          Checks whether the argument term is unified with this one.
 
Methods inherited from class jp.ac.kobe_u.cs.prolog.lang.Term
convertible, dereference, instanceOfTerm, isClosure, isDouble, isInteger, isJavaObject, isList, isNil, isNumber, isStructure, isSymbol, isVariable
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SYM_DOT

protected static SymbolTerm SYM_DOT
A functor '.' /2.


car

protected Term car
Holds the first element of this ListTerm.


cdr

protected Term cdr
Holds the list consisting of all the rest of the elements of this ListTerm but the first one.

Constructor Detail

ListTerm

public ListTerm(Term _car,
                Term _cdr)
Constructs a new Prolog list structure such that _car is the first element of this list, and _cdr is the list consisting of all the rest of the elements of this list but the first one.

Method Detail

car

public Term car()
Returns the value of car.

See Also:
car

cdr

public Term cdr()
Returns the value of cdr.

See Also:
cdr

setCar

public void setCar(Term t)
Sets the value to car.

See Also:
car

setCdr

public void setCdr(Term t)
Sets the value to cdr.

See Also:
cdr

unify

public boolean unify(Term t,
                     Trail trail)
Description copied from class: Term
Checks whether the argument term is unified with this one.

Specified by:
unify in class Term
Parameters:
t - the term to be unified with.
trail - Trail Stack.
Returns:
true if succeeds, otherwise false.

convertible

public boolean convertible(java.lang.Class type)
Description copied from class: Term
Check whether this object is convertible with the given Java class type.

Overrides:
convertible in class Term
Parameters:
type - the Java class type to compare with.
Returns:
the boolean whose value is convertible(Vector.class, type).
See Also:
Term.convertible(Class, Class)

copy

protected Term copy(Prolog engine)
Description copied from class: Term
Returns a copy of this object.

Overrides:
copy in class Term

isGround

public boolean isGround()
Description copied from class: Term
Check whether this term is a ground term.

Overrides:
isGround in class Term
Returns:
true if ground, otherwise false.

length

public int length()
Returns the length of this ListTerm.


toJava

public java.lang.Object toJava()
Returns a java.util.Vector corresponds to this ListTerm according to Prolog Cafe interoperability with Java.

Overrides:
toJava in class Term
Returns:
a java.util.Vector object equivalent to this IntegerTerm.

toQuotedString

public java.lang.String toQuotedString()
Description copied from class: Term
Returns a quoted string representation of this term.

Overrides:
toQuotedString in class Term

equals

public boolean equals(java.lang.Object obj)
Checks term equality of two terms. The result is true if and only if the argument is an instance of ListTerm, and all corresponding pairs of elements in the two lists are term-equal.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare with. This must be dereferenced.
Returns:
true if the given object represents a Prolog list equivalent to this ListTerm, false otherwise.
See Also:
compareTo(jp.ac.kobe_u.cs.prolog.lang.Term)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns a string representation of this ListTerm.

Overrides:
toString in class java.lang.Object

compareTo

public int compareTo(Term anotherTerm)
Compares two terms in Prolog standard order of terms.
It is noted that t1.compareTo(t2) == 0 has the same boolean value as t1.equals(t2).

Parameters:
anotherTerm - the term to compared with. It must be dereferenced.
Returns:
the value 0 if two terms are identical; a value less than 0 if this term is before the anotherTerm; and a value greater than 0 if this term is after the anotherTerm.

Prolog Cafe v1.2

Copyright (C) 1997-2008 M.BANBARA and N.TAMURA