public class SPTerm extends java.lang.Object implements Term
In other words, SPTerm objects are only handles to SP_term_refs. The actual life of an SP_term_ref (and of the Prolog term) are completely independent of the life of an SPTerm object. So, if a SPTerm object is garbage collected, the SP_term_ref and the Prolog term may very well be alive and well inside the Prolog stack. On the other hand, just because an SPTerm object is not GC:d, that does not mean that the Prolog term is still alive. The life-span of SP_term_refs and Prolog terms are explained in detail in the User's Manual Section "SPTerm and Memory".
The methods in this class are encapsulations of the C-functions in the C-Prolog interface which accesses SP_term_refs and their underlying Prolog terms.
You should not inherit from SPTerm.
| Modifier and Type | Field and Description |
|---|---|
static int |
SP_TYPE_ATOM
The term is an atom.
|
static int |
SP_TYPE_COMPOUND
The term is a compound term.
|
static int |
SP_TYPE_FLOAT
The term is a float.
|
static int |
SP_TYPE_INTEGER
The term is an integer.
|
static int |
SP_TYPE_VARIABLE
The term is a variable.
|
TYPE_ATOM, TYPE_COMPOUND, TYPE_FLOAT, TYPE_INTEGER, TYPE_VARIABLE| Constructor and Description |
|---|
SPTerm(SICStus sp)
Creates a null-term (i.e. the empty list, '[]').
|
SPTerm(SICStus sp,
double value)
Creates a term initialized to a Prolog float.
|
SPTerm(SICStus sp,
float value)
Creates a term initialized to a Prolog float.
|
SPTerm(SICStus sp,
int value)
Creates a term initialized to a Prolog integer.
|
SPTerm(SICStus sp,
SPTerm value)
Creates a term initialized to an existing term.
|
SPTerm(SICStus sp,
java.lang.String value)
Creates a term initialized to a Prolog atom.
|
SPTerm(SICStus sp,
java.lang.String functor,
int arity,
SPTerm[] args)
Deprecated.
Do not pass the arity argument.
|
SPTerm(SICStus sp,
java.lang.String functor,
SPTerm[] args)
Creates a term initialized to a Prolog compound term.
|
| Modifier and Type | Method and Description |
|---|---|
void |
CheckValid()
Throws an exception if the term is not valid.
|
void |
CheckValid(SICStus sp) |
int |
compare(Term with)
Compares two terms according to standard order.
|
SPTerm |
consFunctor(java.lang.String functor,
int arity,
SPTerm[] args)
Deprecated.
Use consFunctor without arity argument instead.
|
SPTerm |
consFunctor(java.lang.String functor,
SPTerm[] args)
Assigns the term to a compound term.
|
SPTerm |
consList(SPTerm head,
SPTerm tail)
Assigns the term to a list with given head and tail.
|
void |
delete()
Invalidates the SPTerm object and makes the SP_term_ref available for re-use.
|
Term |
getArg(java.lang.Integer i,
Term arg) |
Term |
getArg(int i,
Term arg)
Gets an argument from a compound term.
|
SPCanonicalAtom |
getCanonicalAtom()
Obtains the canonical representation of a Prolog atom.
|
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()
Returns the object encapsulated in the Prolog term.
|
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 |
isValid(SICStus sp)
As isValid().
|
boolean |
isVariable()
Tests if the term is a variable.
|
SPTerm |
putAtom(long canonical_value)
Deprecated.
Use putCanonicalAtom instead.
|
SPTerm |
putCanonicalAtom(SPCanonicalAtom cAtom)
Assigns the term to a Prolog atom, given the canonical representation of the
atom as an SPCanonicalAtom object.
|
SPTerm |
putEmptyList()
Assigns the term to an empty list
[]. |
SPTerm |
putFloat(double value)
Assigns the term to a Prolog float from a Java
double. |
SPTerm |
putFloat(float value)
Assigns the term to a Prolog float from a Java
float. |
SPTerm |
putFunctor(java.lang.String functor,
int arity)
Assigns the term to a compound term with all arguments initialized to unbound
variables.
|
SPTerm |
putInteger(int value)
Assigns the term to a Prolog integer from a Java
int. |
SPTerm |
putInteger(long value)
Assigns the term to a Prolog integer from a Java
long. |
SPTerm |
putList()
Assigns the term to a list whose head and tail are both unbound variables.
|
SPTerm |
putListChars(java.lang.String string)
Assigns the term to a list of character codes from a Java
String. |
SPTerm |
putNumberChars(java.lang.String string)
Assigns the term to a Prolog number from a string.
|
SPTerm |
putObject(java.lang.Object obj)
Assigns the term to a *global* reference to a Java object.
|
SPTerm |
putString(java.lang.String value)
Assigns the term to a Prolog atom from a Java
String. |
SPTerm |
putTerm(SPTerm new_term)
Assigns the term to another Prolog term.
|
SPTerm |
putVariable()
Assigns the term to an unbound variable.
|
Term[] |
toPrologTermArray()
Converts a list to an array of Terms.
|
java.lang.String |
toString()
Returns a string-representation of a term.
|
java.lang.String |
toString(Term options)
Returns a string-representation of a term.
|
SPTerm[] |
toTermArray()
Converts a list to an array of SPTerm.
|
int |
type()
Returns the type of this term.
|
boolean |
unify(Term with)
Unifies the term with another term.
|
public static final int SP_TYPE_VARIABLE
type(),
Constant Field Valuespublic static final int SP_TYPE_INTEGER
type(),
Constant Field Valuespublic static final int SP_TYPE_ATOM
type(),
Constant Field Valuespublic static final int SP_TYPE_FLOAT
type(),
Constant Field Valuespublic static final int SP_TYPE_COMPOUND
type(),
Constant Field Valuespublic SPTerm(SICStus sp)
sp - Pointer to the SICStus object.public SPTerm(SICStus sp, SPTerm value) throws IllegalTermException, ConversionFailedException
sp - Pointer to the SICStus object.value - The SPTerm object whose term to useIllegalTermException - an illegal term was detectedConversionFailedException - the term could not be created, for some reasonputTerm(se.sics.jasper.SPTerm)public SPTerm(SICStus sp, int value)
sp - Pointer to the SICStus object.value - Initial value of the integer.putInteger(int)public SPTerm(SICStus sp, double value)
sp - Pointer to the SICStus object.value - Initial value of the float.putFloat(double)public SPTerm(SICStus sp, float value)
sp - Pointer to the SICStus object.value - Initial value of the float.putFloat(double)public SPTerm(SICStus sp, java.lang.String value) throws ConversionFailedException
sp - Pointer to the SICStus object.value - String describing the initial value of the atom.ConversionFailedException - the term could not be created, for some reasonputString(java.lang.String)public SPTerm(SICStus sp, java.lang.String functor, SPTerm[] args) throws ConversionFailedException, IllegalTermException
sp - Pointer to the SICStus object.functor - The functor of the compound term as a stringargs - The arguments as an array of SPTerm:sConversionFailedException - the term could not be created, for some reasonIllegalTermException - an illegal term was detectedconsFunctor(java.lang.String, se.sics.jasper.SPTerm[])@Deprecated public SPTerm(SICStus sp, java.lang.String functor, int arity, SPTerm[] args) throws ConversionFailedException, IllegalTermException
sp - Pointer to the SICStus object.functor - The functor of the compound term as a stringarity - The arity of the compound term (ignored)args - The arguments as an SPTerm array.ConversionFailedException - the term could not be created, for some reasonIllegalTermException - an illegal term was detectedconsFunctor(java.lang.String, se.sics.jasper.SPTerm[])public void delete()
throws SPException
delete in interface TermSPExceptionSICStus.setReuseTermRefs(boolean)public boolean isValid()
delete, closing, cutting or asking for the nextSolution of an enclosing
SPQuery.public boolean isValid(SICStus sp)
sp - the Prolog that the term should be validated againstpublic void CheckValid()
throws IllegalTermException
IllegalTermException - an illegal term was detectedisValid()public void CheckValid(SICStus sp) throws IllegalTermException
sp - the Prolog instance to checkIllegalTermException - if the argument was invalidpublic int type()
throws IllegalTermException
SP_TYPE_INTEGER, SP_TYPE_FLOAT,
SP_TYPE_ATOM, SP_TYPE_VARIABLE, and
SP_TYPE_COMPOUNDtype in interface TermIllegalTermExceptionSP_TYPE_INTEGER,
SP_TYPE_ATOM,
SP_TYPE_FLOAT,
SP_TYPE_VARIABLE,
SP_TYPE_COMPOUND,
isVariable(),
isInteger(),
isAtom(),
isFloat(),
isCompound(),
isList(),
isAtomic(),
isNumber()public boolean isVariable()
throws IllegalTermException
isVariable in interface Termtrue if the term is a variable; false
otherwiseIllegalTermExceptionpublic boolean isInteger()
throws IllegalTermException
isInteger in interface Termtrue if the term is an integer; false
otherwiseIllegalTermExceptionpublic boolean isAtom()
throws IllegalTermException
isAtom in interface Termtrue if the term is an atom; false
otherwiseIllegalTermExceptionpublic boolean isFloat()
throws IllegalTermException
isFloat in interface Termtrue if the term is a float; false
otherwiseIllegalTermExceptionpublic boolean isCompound()
throws IllegalTermException
isCompound in interface Termtrue if the term is a compound term; false
otherwiseIllegalTermExceptionpublic boolean isList()
throws IllegalTermException
isList(T) :- nonvar(T), T=[_|_].isList in interface Termtrue if the term is a list cell; false
otherwiseIllegalTermExceptionpublic boolean isEmptyList()
throws IllegalTermException
isEmptyList in interface Termtrue if the term is the atom [];
false otherwiseIllegalTermExceptionpublic boolean isAtomic()
throws IllegalTermException
isAtomic in interface Termtrue if the term is atomic; false otherwiseIllegalTermExceptionpublic boolean isNumber()
throws IllegalTermException
isNumber in interface Termtrue if the term is a number; false
otherwiseIllegalTermExceptionpublic SPTerm putVariable() throws ConversionFailedException, IllegalTermException
ConversionFailedException - The term could not be converted to a variable.IllegalTermException - an illegal term was detectedpublic SPTerm putInteger(int value) throws ConversionFailedException, IllegalTermException
int.value - The value of the integerConversionFailedException - The term could not be converted to a integer.IllegalTermException - an illegal term was detectedpublic SPTerm putInteger(long value) throws ConversionFailedException, IllegalTermException
long.value - The value of the integerConversionFailedException - The term could not be converted to a integer.IllegalTermException - an illegal term was detectedpublic SPTerm putFloat(double value) throws ConversionFailedException, IllegalTermException
double.value - The value of the floatConversionFailedException - The term could not be converted to a float.IllegalTermException - an illegal term was detectedpublic SPTerm putFloat(float value) throws ConversionFailedException, IllegalTermException
float.value - The value of the floatConversionFailedException - The term could not be converted to a float.IllegalTermException - an illegal term was detectedpublic SPTerm putString(java.lang.String value) throws ConversionFailedException, IllegalTermException
String.value - The value of the atom as a StringConversionFailedException - The term could not be converted to an atom.IllegalTermException - an illegal term was detectedpublic SPTerm putEmptyList() throws ConversionFailedException, IllegalTermException
[].ConversionFailedException - the term could not be created, for some reasonIllegalTermException - an illegal term was detected@Deprecated public SPTerm putAtom(long canonical_value) throws ConversionFailedException, IllegalTermException
long.canonical_value - The canonical representation of an atom.ConversionFailedException - The term could not be converted to an atom.IllegalTermException - an illegal term was detectedpublic SPTerm putCanonicalAtom(SPCanonicalAtom cAtom) throws ConversionFailedException, IllegalTermException
cAtom - The canonical representation of an atom.ConversionFailedException - The term could not be converted to an atom.IllegalTermException - an illegal term was detectedSPCanonicalAtompublic SPTerm putObject(java.lang.Object obj) throws ConversionFailedException, IllegalTermException
obj - A reference to a Java object.ConversionFailedException - The term could not be converted to a Java object reference.IllegalTermException - an illegal term was detectedpublic java.lang.Object getObject()
throws se.sics.jasper.NativeCodeException,
IllegalTermException
putObject(java.lang.Object).getObject in interface Termse.sics.jasper.NativeCodeExceptionIllegalTermExceptionpublic SPTerm putTerm(SPTerm new_term) throws ConversionFailedException, IllegalTermException
new_term - The term's new valueConversionFailedException - The term could not be converted to another term.IllegalTermException - an illegal term was detectedpublic SPTerm putListChars(java.lang.String string) throws ConversionFailedException, IllegalTermException
String.string - The String objectConversionFailedException - The term could not be converted to list of characters.IllegalTermException - an illegal term was detectedpublic SPTerm putNumberChars(java.lang.String string) throws ConversionFailedException, IllegalTermException
string - The string containing the printed representation of the number.ConversionFailedException - The term could not be converted to number.IllegalTermException - an illegal term was detectedpublic SPTerm putFunctor(java.lang.String functor, int arity) throws ConversionFailedException, IllegalTermException
functor - The term's functor as a Java Stringarity - The term's arityConversionFailedException - The term could not be converted to compound term.IllegalTermException - an illegal term was detectedpublic SPTerm consFunctor(java.lang.String functor, SPTerm[] args) throws ConversionFailedException, IllegalTermException
functor - The term's functor as a Java Stringargs - The arguments of the termConversionFailedException - The term could not be converted to compound term.IllegalTermException - an illegal term was detected@Deprecated public SPTerm consFunctor(java.lang.String functor, int arity, SPTerm[] args) throws ConversionFailedException, IllegalTermException
functor - The term's functor as a Java Stringarity - The term's arity (ignored)args - The arguments of the termConversionFailedException - The term could not be converted to compound term.IllegalTermException - an illegal term was detectedpublic SPTerm putList() throws ConversionFailedException, IllegalTermException
ConversionFailedException - The term could not be converted to an empty list.IllegalTermException - an illegal term was detectedpublic SPTerm consList(SPTerm head, SPTerm tail) throws ConversionFailedException, IllegalTermException
head - The head of the listtail - The tail of the listConversionFailedException - The term could not be converted to list.IllegalTermException - an illegal term was detectedpublic long getInteger()
throws ConversionFailedException,
IllegalTermException
getInteger in interface Termlong.ConversionFailedException - The term could not be converted to an integer.IllegalTermExceptionpublic double getDouble()
throws ConversionFailedException,
IllegalTermException
getDouble in interface Termdouble.ConversionFailedException - The term could not be converted to a double.IllegalTermException - an illegal term was detectedpublic SPCanonicalAtom getCanonicalAtom() throws ConversionFailedException, AtomRegisterFailure, IllegalTermException
ConversionFailedException - The term could not be converted to the canonical representation
of an atom.AtomRegisterFailure - the atom could not be registered for some reasonIllegalTermException - an illegal term was detectedSPCanonicalAtompublic java.lang.String getString()
throws ConversionFailedException,
IllegalTermException
getString in interface TermString.ConversionFailedException - The term could not be converted to a string.IllegalTermExceptionpublic java.lang.String getListChars()
throws ConversionFailedException,
IllegalTermException
getListChars in interface TermString.ConversionFailedException - The term could not be converted to a list of characters.IllegalTermExceptionpublic java.lang.String getNumberChars()
throws ConversionFailedException,
IllegalTermException
getNumberChars in interface TermString.ConversionFailedException - The term could not be converted to a number.IllegalTermExceptionpublic java.lang.String getFunctorName()
throws ConversionFailedException,
IllegalTermException
getFunctorName in interface TermString.ConversionFailedException - The term could not be converted to the name of a functor.IllegalTermException - an illegal term was detectedpublic int getFunctorArity()
throws ConversionFailedException,
IllegalTermException
getFunctorArity in interface Termint.ConversionFailedException - The term could not be converted to the arity of a functor.IllegalTermException - an illegal term was detectedpublic Term getList(Term head, Term tail) throws ConversionFailedException, IllegalTermException
getList in interface Termhead - The term which will be assigned the headtail - The term which will be assigned the tailConversionFailedException - The term could not be converted to a list.IllegalTermExceptionpublic Term getArg(java.lang.Integer i, Term arg) throws ConversionFailedException, IllegalTermException
i - The number of the argument.arg - The term to which the ith argument will be
assigned.ConversionFailedException - The term could not be converted to the argument of a compound
term.IllegalTermException - an invalid term was detectedpublic Term getArg(int i, Term arg) throws ConversionFailedException, IllegalTermException
arg/3
with the third argument unbound.getArg in interface Termi - The number of the argument.arg - The term to which the ith argument will be
assigned.ConversionFailedException - The term could not be converted to the argument of a compound
term.IllegalTermExceptionpublic boolean unify(Term with) throws IllegalTermException
unify in interface Termwith - The term with which to unify.IllegalTermExceptionpublic int compare(Term with) throws IllegalTermException
compare in interface Termwith - The term to compare with.x < y, 0 if x == y, and 1 if
x > y.IllegalTermException - an illegal term was detectedpublic java.lang.String toString()
public java.lang.String toString(Term options) throws SPException
TermtoString in interface Termoptions - the options that are passed do write_term/3SPException - A Prolog exception was thrown.public SPTerm[] toTermArray() throws ConversionFailedException, IllegalTermException
ConversionFailedException - If the term could not be converted to a list.IllegalTermException - an illegal term was detectedpublic Term[] toPrologTermArray() throws ConversionFailedException, IllegalTermException
TermtoPrologTermArray in interface TermConversionFailedExceptionIllegalTermException