|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--se.sics.jasper.SPTerm
SPTerms are Java representations of Prolog terms. SPTerms do not contain Prolog terms themselves; Prolog terms are always stored on the Prolog heap. Instead, an SPTerm object contains an SP_term_ref which is an index into a stack maintained by Prolog. This stack in turn contains references into the Prolog heap. For more information, consult the section on "Mixing Java and Prolog" in the SICStus Prolog User's Manual.
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
.
Field Summary | |
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. |
Fields inherited from interface se.sics.jasper.Term |
TYPE_ATOM, TYPE_COMPOUND, TYPE_FLOAT, TYPE_INTEGER, TYPE_VARIABLE |
Constructor Summary | |
SPTerm(SICStus sp)
Creates a null-term (i.e. |
|
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. |
Method Summary | |
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 compount 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(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-respresentation 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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int SP_TYPE_VARIABLE
type()
public static final int SP_TYPE_INTEGER
type()
public static final int SP_TYPE_ATOM
type()
public static final int SP_TYPE_FLOAT
type()
public static final int SP_TYPE_COMPOUND
type()
Constructor Detail |
public 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 useputTerm(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.putString(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:sconsFunctor(java.lang.String, se.sics.jasper.SPTerm[])
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.consFunctor(java.lang.String, se.sics.jasper.SPTerm[])
Method Detail |
public void delete() throws SPException
delete
in interface Term
SICStus.setReuseTermRefs(boolean)
public boolean isValid()
delete
, closing,
cutting or asking for the nextSolution of an enclosing SPQuery.isValid
in interface Term
true
if still valid; false
otherwise.
The result is only guaranteed to remain valid while inside a block
synchronized on the SICStus object.public boolean isValid(SICStus sp)
public void CheckValid() throws IllegalTermException
isValid()
public void CheckValid(SICStus sp) throws IllegalTermException
public int type() throws IllegalTermException
SP_TYPE_INTEGER
, SP_TYPE_FLOAT
,
SP_TYPE_ATOM
, SP_TYPE_VARIABLE
,
and SP_TYPE_COMPOUND
type
in interface Term
SP_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 Term
true
if the term is a variable; false
otherwisepublic boolean isInteger() throws IllegalTermException
isInteger
in interface Term
true
if the term is an integer; false
otherwisepublic boolean isAtom() throws IllegalTermException
isAtom
in interface Term
true
if the term is an atom; false
otherwisepublic boolean isFloat() throws IllegalTermException
isFloat
in interface Term
true
if the term is a float; false
otherwisepublic boolean isCompound() throws IllegalTermException
isCompound
in interface Term
true
if the term is a compound term;
false
otherwisepublic boolean isList() throws IllegalTermException
isList(T) :- nonvar(T), T=[_|_].
isList
in interface Term
true
if the term is a list cell; false
otherwisepublic boolean isEmptyList() throws IllegalTermException
isEmptyList
in interface Term
true
if the term is the atom []
; false
otherwisepublic boolean isAtomic() throws IllegalTermException
isAtomic
in interface Term
true
if the term is atomic; false
otherwisepublic boolean isNumber() throws IllegalTermException
isNumber
in interface Term
true
if the term is a number; false
otherwisepublic SPTerm putVariable() throws ConversionFailedException, IllegalTermException
ConversionFailedException
- The term could not be
converted to a variable.public SPTerm putInteger(int value) throws ConversionFailedException, IllegalTermException
int
.value
- The value of the integerConversionFailedException
- The term could not be
converted to a integer.public SPTerm putInteger(long value) throws ConversionFailedException, IllegalTermException
long
.value
- The value of the integerConversionFailedException
- The term could not be
converted to a integer.public SPTerm putFloat(double value) throws ConversionFailedException, IllegalTermException
double
.value
- The value of the floatConversionFailedException
- The term could not be
converted to a float.public SPTerm putFloat(float value) throws ConversionFailedException, IllegalTermException
float
.value
- The value of the floatConversionFailedException
- The term could not be
converted to a float.public 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.public SPTerm putEmptyList() throws ConversionFailedException, IllegalTermException
[]
.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.public SPTerm putCanonicalAtom(SPCanonicalAtom cAtom) throws ConversionFailedException, IllegalTermException
cAtom
- The canonical representation of an atom.ConversionFailedException
- The term could not be
converted to an atom.SPCanonicalAtom
public 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.public java.lang.Object getObject() throws se.sics.jasper.NativeCodeException, IllegalTermException
putObject(java.lang.Object)
.getObject
in interface Term
public SPTerm putTerm(SPTerm new_term) throws ConversionFailedException, IllegalTermException
new_term
- The term's new valueConversionFailedException
- The term could not be
converted to another term.public SPTerm putListChars(java.lang.String string) throws ConversionFailedException, IllegalTermException
String
.string
- The String objectConversionFailedException
- The term could not be
converted to list of characters.public 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.public SPTerm putFunctor(java.lang.String functor, int arity) throws ConversionFailedException, IllegalTermException
functor
- The term's functor as a Java String
arity
- The term's arityConversionFailedException
- The term could not be
converted to compound term.public SPTerm consFunctor(java.lang.String functor, SPTerm[] args) throws ConversionFailedException, IllegalTermException
functor
- The term's functor as a Java String
args
- The arguments of the termConversionFailedException
- The term could not be
converted to compound term.public SPTerm consFunctor(java.lang.String functor, int arity, SPTerm[] args) throws ConversionFailedException, IllegalTermException
functor
- The term's functor as a Java String
arity
- The term's arity (ignored)args
- The arguments of the termConversionFailedException
- The term could not be
converted to compound term.public SPTerm putList() throws ConversionFailedException, IllegalTermException
ConversionFailedException
- The term could not be
converted to an empty list.public 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.public long getInteger() throws ConversionFailedException, IllegalTermException
getInteger
in interface Term
long
.ConversionFailedException
- The term could not be
converted to an integer.public double getDouble() throws ConversionFailedException, IllegalTermException
getDouble
in interface Term
double
.ConversionFailedException
- The term could not be
converted to a double.public SPCanonicalAtom getCanonicalAtom() throws ConversionFailedException, AtomRegisterFailure, IllegalTermException
ConversionFailedException
- The term could not be
converted to the canonical representation of an atom.AtomRegisterFailure
- SPCanonicalAtom
public java.lang.String getString() throws ConversionFailedException, IllegalTermException
getString
in interface Term
String
.ConversionFailedException
- The term could not be
converted to a string.public java.lang.String getListChars() throws ConversionFailedException, IllegalTermException
getListChars
in interface Term
String
.ConversionFailedException
- The term could not be
converted to a list of characters.public java.lang.String getNumberChars() throws ConversionFailedException, IllegalTermException
getNumberChars
in interface Term
String
.ConversionFailedException
- The term could not be
converted to a number.public java.lang.String getFunctorName() throws ConversionFailedException, IllegalTermException
getFunctorName
in interface Term
String
.ConversionFailedException
- The term could not be
converted to the name of a functor.public int getFunctorArity() throws ConversionFailedException, IllegalTermException
getFunctorArity
in interface Term
int
.ConversionFailedException
- The term could not be
converted to the arity of a functor.public Term getList(Term head, Term tail) throws ConversionFailedException, IllegalTermException
getList
in interface Term
head
- 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.public Term getArg(int i, Term arg) throws ConversionFailedException, IllegalTermException
arg/3
with the third argument unbound.getArg
in interface Term
i
- The number of the argument.arg
- The term to which the i
th argument will be
assigned.ConversionFailedException
- The term could not be
converted to the argument of a compound term.public boolean unify(Term with) throws IllegalTermException
unify
in interface Term
with
- The term with which to unify.public int compare(Term with) throws IllegalTermException
compare
in interface Term
with
- The term to compare with.x < y
, 0 if x == y
, and 1 if
x > y
.public java.lang.String toString()
toString
in interface Term
toString
in class java.lang.Object
public java.lang.String toString(Term options) throws SPException
Term
toString
in interface Term
public SPTerm[] toTermArray() throws ConversionFailedException, IllegalTermException
ConversionFailedException
- If the term
could not be converted to a list.public Term[] toPrologTermArray() throws ConversionFailedException, IllegalTermException
Term
toPrologTermArray
in interface Term
se.sics.jasper.Term
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |