se.sics.jasper
Interface Term

All Known Implementing Classes:
SPTerm

public interface Term

Terms are Java representations of Prolog terms. See SPTerm for more information on the implementation.


Field Summary
static int TYPE_ATOM
          The term is an atom.
static int TYPE_COMPOUND
          The term is a compound term.
static int TYPE_FLOAT
          The term is a float.
static int TYPE_INTEGER
          The term is an integer.
static int TYPE_VARIABLE
          The term is a variable.
 
Method Summary
 int compare(Term with)
          Compares two terms according to standard order.
 void delete()
          Invalidates the Term object and make the SP_term_ref available for re-use.
 Term getArg(int i, Term arg)
          Gets an argument from a compound term.
 double getDouble()
          Obtains the value of the Prolog float.
 int getFunctorArity()
          Obtains the arity of a functor.
 java.lang.String getFunctorName()
          Obtains the name of a functor.
 long getInteger()
          Obtains the integer value of the Prolog term.
 Term getList(Term head, Term tail)
          Gets the head and tail of a Prolog list.
 java.lang.String getListChars()
          Obtains the value of a list of characters as a string.
 java.lang.String getNumberChars()
          Obtains the value of a Prolog number as a string.
 java.lang.Object getObject()
          Not yet implemented in Multi threaded Jasper.
 java.lang.String getString()
          Obtains the value of the Prolog atom as a string.
 boolean isAtom()
          Tests if the term is an atom.
 boolean isAtomic()
          Tests if the term is atomic.
 boolean isCompound()
          Tests if the term is a compound term.
 boolean isEmptyList()
          Tests if the term is the empty list.
 boolean isFloat()
          Tests if the term is a float.
 boolean isInteger()
          Tests if the term is an integer.
 boolean isList()
          Tests if the term is a list cell.
 boolean isNumber()
          Tests if the term is a number.
 boolean isValid()
          Tests if the Prolog term referenced is still accessible through this object.
 boolean isVariable()
          Tests if the term is a variable.
 Term[] toPrologTermArray()
          Converts a list to an array of Terms.
 java.lang.String toString()
          Returns a string-respresentation of a term.
 java.lang.String toString(Term options)
          Returns a string-respresentation of a term.
 int type()
          Returns the type of this term.
 boolean unify(Term with)
          Unifies the term with another term.
 

Field Detail

TYPE_VARIABLE

public static final int TYPE_VARIABLE
The term is a variable.
See Also:
type()

TYPE_INTEGER

public static final int TYPE_INTEGER
The term is an integer.
See Also:
type()

TYPE_ATOM

public static final int TYPE_ATOM
The term is an atom.
See Also:
type()

TYPE_FLOAT

public static final int TYPE_FLOAT
The term is a float.
See Also:
type()

TYPE_COMPOUND

public static final int TYPE_COMPOUND
The term is a compound term.
See Also:
type()
Method Detail

compare

public int compare(Term with)
            throws IllegalTermException,
                   java.lang.Exception
Compares two terms according to standard order.
Parameters:
with - The term to compare with.
Returns:
-1 if x < y, 0 if x == y, and 1 if x > y.

delete

public void delete()
            throws java.lang.Exception
Invalidates the Term object and make the SP_term_ref available for re-use. Accessing an invalid Term object throws IllegalTermException.

getArg

public Term getArg(int i,
                   Term arg)
            throws java.lang.InterruptedException,
                   java.lang.Exception
Gets an argument from a compound term. Similar to calling arg/3 with the third argument unbound.
Parameters:
i - The number of the argument.
arg - The term to which the ith argument will be assigned.
Returns:
A reference to itself.

getDouble

public double getDouble()
                 throws ConversionFailedException,
                        IllegalTermException,
                        java.lang.Exception
Obtains the value of the Prolog float.
Returns:
The value of the Prolog float as a Java double.
Throws:
ConversionFailedException - The term could not be converted to a double.

getFunctorArity

public int getFunctorArity()
                    throws ConversionFailedException,
                           IllegalTermException,
                           java.lang.Exception
Obtains the arity of a functor.
Returns:
The arity of a functor as a Java int.
Throws:
ConversionFailedException - The term could not be converted to the arity of a functor.

getFunctorName

public java.lang.String getFunctorName()
                                throws ConversionFailedException,
                                       IllegalTermException,
                                       java.lang.Exception
Obtains the name of a functor.
Returns:
The functor as a Java String.
Throws:
ConversionFailedException - The term could not be converted to the name of a functor.

getInteger

public long getInteger()
                throws java.lang.Exception
Obtains the integer value of the Prolog term.
Returns:
The value of the Prolog term as a Java long.

getList

public Term getList(Term head,
                    Term tail)
             throws java.lang.InterruptedException,
                    java.lang.Exception
Gets the head and tail of a Prolog list.
Parameters:
head - The term which will be assigned the head
tail - The term which will be assigned the tail
Returns:
A reference to itself.

getListChars

public java.lang.String getListChars()
                              throws java.lang.Exception
Obtains the value of a list of characters as a string.
Returns:
The value of the list as a Java String.

getNumberChars

public java.lang.String getNumberChars()
                                throws java.lang.Exception
Obtains the value of a Prolog number as a string.
Returns:
The value of the number as a Java String.

getObject

public java.lang.Object getObject()
                           throws java.lang.Exception
Not yet implemented in Multi threaded Jasper. (I.e. it is a no-op in MT-Jasper).

See SPTerm.getObject() for documentation on the single threaded implementation.


getString

public java.lang.String getString()
                           throws java.lang.Exception
Obtains the value of the Prolog atom as a string.
Returns:
The value of the Prolog atom as a Java String.

isAtom

public boolean isAtom()
               throws java.lang.Exception
Tests if the term is an atom.
Returns:
true if the term is an atom; false otherwise

isAtomic

public boolean isAtomic()
                 throws java.lang.Exception
Tests if the term is atomic. A term is atomic if it is instantiated to an atom or a number.
Returns:
true if the term is atomic; false otherwise

isCompound

public boolean isCompound()
                   throws java.lang.Exception
Tests if the term is a compound term.
Returns:
true if the term is a compound term; false otherwise

isEmptyList

public boolean isEmptyList()
                    throws java.lang.Exception
Tests if the term is the empty list.
Returns:
true if the term is the atom []; false otherwise

isFloat

public boolean isFloat()
                throws java.lang.Exception
Tests if the term is a float.
Returns:
true if the term is a float; false otherwise

isInteger

public boolean isInteger()
                  throws java.lang.Exception
Tests if the term is an integer.
Returns:
true if the term is an integer; false otherwise

isList

public boolean isList()
               throws java.lang.Exception
Tests if the term is a list cell. Equivalent to the Prolog code isList(T) :- nonvar(T), T=[_|_].
Returns:
true if the term is a list cell; false otherwise

isNumber

public boolean isNumber()
                 throws java.lang.Exception
Tests if the term is a number. A number is a term instantiated to an integer or a float.
Returns:
true if the term is a number; false otherwise

isValid

public boolean isValid()
                throws java.lang.Exception
Tests if the Prolog term referenced is still accessible through this object. Term object becomes invalid as the result of of explicit delete, closing, cutting or asking for the nextSolution of an enclosing SPQuery.
Returns:
true if still valid; false otherwise.

isVariable

public boolean isVariable()
                   throws java.lang.Exception
Tests if the term is a variable.
Returns:
true if the term is a variable; false otherwise

toString

public java.lang.String toString()
Returns a string-respresentation of a term.
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(Term options)
                          throws SPException,
                                 java.lang.Exception
Returns a string-respresentation of a term. This is an interface to write_term/3, which see.

toPrologTermArray

public Term[] toPrologTermArray()
                         throws java.lang.Exception
Converts a list to an array of Terms. Useful when examining lists returned from Prolog queries. This is of course only possible on a list.
Returns:
An array of the terms.

type

public int type()
         throws java.lang.Exception
Returns the type of this term. The return value is as defined by the constants TYPE_INTEGER, TYPE_FLOAT, TYPE_ATOM, TYPE_VARIABLE, and TYPE_COMPOUND
See Also:
TYPE_INTEGER, TYPE_ATOM, TYPE_FLOAT, TYPE_VARIABLE, TYPE_COMPOUND, isVariable(), isInteger(), isAtom(), isFloat(), isCompound(), isList(), isAtomic(), isNumber()

unify

public boolean unify(Term with)
              throws java.lang.Exception
Unifies the term with another term.
Parameters:
with - The term with which to unify.
Returns:
True/False depending on whether the unification succeeded.