|
||||||||
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 a SPTerm object contains a so-called term-reference (often abbreviated 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 on term-refs, consult the section on "Mixing C and Prolog" in the SICStus Prolog User's Manual.
In other words, SPTerm objects are only handles to term-refs. The actual life of a term-ref (and of the Prolog term) are completely independent of the life of a SPTerm object. So, if a SPTerm object is garbage collected, the term-ref and the Prolog term may very well be alive and well inside the Prolog stack. On the other hand, just because a SPTerm object is not GC:d, that does not mean that the Prolog term is still alive. The life-span of term-refs are explained in detail in the User's Manual. The methods in this class are encapsulations of the C-functions in the C-Prolog interface which accesses term-refs and their underlying Prolog terms.
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 a integer. |
static int |
SP_TYPE_VARIABLE
The term is a variable. |
Constructor Summary | |
SPTerm()
Creates a null-term, but doesn't require a pointer to the SICStus object. |
|
SPTerm(long nativeTermRef)
Creates a term given only the native term ref. |
|
SPTerm(SICStus sp)
Creates a null-term. |
|
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,
java.lang.String value)
Creates a term initialized to a Prolog atom. |
|
SPTerm(SICStus sp,
java.lang.String functor,
int arity,
SPTerm[] args)
Creates a term initialized to a Prolog compound term. |
Method Summary | |
int |
compare(SPTerm with)
Compare two terms according to standard order. |
SPTerm |
consFunctor(java.lang.String functor,
int arity,
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. |
SPTerm |
getArg(int i,
SPTerm arg)
Get an argument from a compound term. |
long |
getAtom()
Deprecated. Use getCanonicalAtom instead. |
SPCanonicalAtom |
getCanonicalAtom()
Obtain the canonical representation of a Prolog atom. |
double |
getDouble()
Obtain the value of the Prolog float. |
int |
getFunctorArity()
Obtain the arity of a functor. |
java.lang.String |
getFunctorName()
Obtain the name of a functor. |
long |
getInteger()
Obtain the integer value of the Prolog term. |
SPTerm |
getList(SPTerm head,
SPTerm tail)
Get the head and tail of a Prolog list. |
java.lang.String |
getListChars()
Obtain the value of a list of characters as a string. |
java.lang.String |
getNumberChars()
Obtain 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()
Obtain 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 |
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. |
boolean |
isNumber()
Tests if the term is a number. |
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 a SPCanonicalAtom object. |
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 |
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 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. |
java.lang.String |
toString()
Returns a string-respresentation of a term. |
SPTerm[] |
toTermArray()
Converts a list to an array of SPTerm. |
int |
type()
Returns the type of this term. |
boolean |
unify(SPTerm with)
Unify 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) throws IllegalCallerException
sp
- Pointer to the SICStus object.public SPTerm(SICStus sp, int value) throws IllegalCallerException
sp
- Pointer to the SICStus object.value
- Initial value of the integer.putInteger(int)
public SPTerm(SICStus sp, double value) throws IllegalCallerException
sp
- Pointer to the SICStus object.value
- Initial value of the float.putFloat(double)
public SPTerm(SICStus sp, float value) throws IllegalCallerException
sp
- Pointer to the SICStus object.value
- Initial value of the float.putFloat(double)
public SPTerm(SICStus sp, java.lang.String value) throws IllegalCallerException
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, int arity, SPTerm[] args) throws IllegalCallerException
sp
- Pointer to the SICStus object.functor
- The functor of the compound term as a stringarity
- The arity of the compound termargs
- The arguments as an array of SPTerm:sconsFunctor(java.lang.String, int, se.sics.jasper.SPTerm[])
public SPTerm(long nativeTermRef) throws IllegalCallerException
public SPTerm() throws IllegalCallerException
Method Detail |
public int type()
SP_TYPE_INTEGER
, SP_TYPE_FLOAT
,
SP_TYPE_ATOM
, SP_TYPE_VARIABLE
,
and SP_TYPE_COMPOUND
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()
true
if the term is a variable; false
otherwisepublic boolean isInteger()
true
if the term is an integer; false
otherwisepublic boolean isAtom()
true
if the term is an atom; false
otherwisepublic boolean isFloat()
true
if the term is a float; false
otherwisepublic boolean isCompound()
true
if the term is a compound term;
false
otherwisepublic boolean isList()
true
if the term is a list; false
otherwisepublic boolean isAtomic()
true
if the term is atomic; false
otherwisepublic boolean isNumber()
true
if the term is a number; false
otherwisepublic SPTerm putVariable() throws ConversionFailedException, IllegalCallerException
public SPTerm putInteger(int value) throws ConversionFailedException, IllegalCallerException
int
.value
- The value of the integerpublic SPTerm putFloat(double value) throws ConversionFailedException, IllegalCallerException
double
.value
- The value of the floatpublic SPTerm putFloat(float value) throws ConversionFailedException, IllegalCallerException
float
.value
- The value of the floatpublic SPTerm putString(java.lang.String value) throws ConversionFailedException, IllegalCallerException
String
.value
- The value of the atom as a Stringpublic SPTerm putAtom(long canonical_value) throws ConversionFailedException, IllegalCallerException
long
.value
- The canonical representation of an atom.public SPTerm putCanonicalAtom(SPCanonicalAtom cAtom) throws ConversionFailedException, IllegalCallerException
value
- The canonical representation of an atom.SPCanonicalAtom
public SPTerm putObject(java.lang.Object obj) throws ConversionFailedException, IllegalCallerException
obj
- A reference to a Java object.public java.lang.Object getObject() throws se.sics.jasper.NativeCodeException, IllegalCallerException
public SPTerm putTerm(SPTerm new_term) throws ConversionFailedException, IllegalCallerException
value
- The term's new valuepublic SPTerm putListChars(java.lang.String string) throws ConversionFailedException, IllegalCallerException
String
.value
- The list of character codespublic SPTerm putNumberChars(java.lang.String string) throws ConversionFailedException, IllegalCallerException
value
- The string containing the printed representation of the number.public SPTerm putFunctor(java.lang.String functor, int arity) throws ConversionFailedException, IllegalCallerException
functor
- The term's functor as a Java String
arity
- The term's aritypublic SPTerm consFunctor(java.lang.String functor, int arity, SPTerm[] args) throws ConversionFailedException, IllegalCallerException
functor
- The term's functor as a Java String
arity
- The term's arityargs
- The arguments of the termpublic SPTerm putList() throws ConversionFailedException, IllegalCallerException
public SPTerm consList(SPTerm head, SPTerm tail) throws ConversionFailedException, IllegalCallerException
head
- The head of the listtail
- The tail of the listpublic long getInteger() throws ConversionFailedException, IllegalCallerException
long
.public double getDouble() throws ConversionFailedException, IllegalCallerException
double
.public long getAtom() throws ConversionFailedException, IllegalCallerException
long
.public SPCanonicalAtom getCanonicalAtom() throws ConversionFailedException, IllegalCallerException, AtomRegisterFailure
SPCanonicalAtom
public java.lang.String getString() throws ConversionFailedException, IllegalCallerException
String
.public java.lang.String getListChars() throws ConversionFailedException, IllegalCallerException
String
.public java.lang.String getNumberChars() throws ConversionFailedException, IllegalCallerException
String
.public java.lang.String getFunctorName() throws ConversionFailedException, IllegalCallerException
String
.public int getFunctorArity() throws ConversionFailedException, IllegalCallerException
int
.public SPTerm getList(SPTerm head, SPTerm tail) throws ConversionFailedException, IllegalCallerException
head
- The term which will be assigned the headtail
- The term which will be assigned the tailpublic SPTerm getArg(int i, SPTerm arg) throws ConversionFailedException, IllegalCallerException
arg/3
with the third argument unbound.i
- The number of the argument.arg
- The term to which the th argument will be assigned.public boolean unify(SPTerm with) throws IllegalCallerException
with
- The term with which to unify.public int compare(SPTerm with) throws IllegalCallerException
with
- The term to compare with.x @< y
, 0 if x == y
, and 1 if
x @> y
.public java.lang.String toString()
public SPTerm[] toTermArray() throws ConversionFailedException, IllegalCallerException
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |