public abstract class Term
extends java.lang.Object
Copyright (C) 1998 Fred Dushin
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Modifier | Constructor and Description |
---|---|
protected |
Term()
This default constructor enables subclasses to define their own default constructors
|
Modifier and Type | Method and Description |
---|---|
Term |
arg(int i)
returns the i-th (1+) argument of a Term;
defined only for Compound
|
Term[] |
args()
The arguments of this Term.
|
int |
arity()
the arity of a Compound, Atom, Integer or Float
|
static java.lang.String[] |
atomListToStringArray(Term t)
Converts a term representing a list of atoms into an array of Strings, each element
in the array being a String for the corresponding atom
e.g., [a, b, 1
|
java.lang.String |
atomType() |
java.math.BigInteger |
bigValue()
the value (as a java.math.BigInteger) of an Integer, whether or not it is big
|
double |
doubleValue()
the value (as a double) of an Integer or Float
|
float |
floatValue()
the value (as a float) of an Integer or Float
|
protected void |
getSubst(java.util.Map<java.lang.String,Term> varnames_to_Terms,
java.util.Map<term_t,Variable> vars_to_Vars)
This method computes a substitution from a Term (the current object).
|
protected static void |
getSubsts(java.util.Map<java.lang.String,Term> varnames_to_Terms,
java.util.Map<term_t,Variable> vars_to_Vars,
Term[] args)
Just calls computeSubstitution for each Term in the array.
|
protected static Term |
getTerm(java.util.Map<term_t,Variable> vars_to_Vars,
term_t term)
create and return a org.jpl7.Term representation of the given Prolog term
|
protected static Term |
getTerm(term_t term) |
boolean |
hasFunctor(java.math.BigInteger name,
int arity)
Tests whether this Term's functor has 'name' and 'arity'
|
boolean |
hasFunctor(double name,
int arity)
Tests whether this Term's functor has 'name' and 'arity'
|
boolean |
hasFunctor(long name,
int arity)
Tests whether this Term's functor has 'name' and 'arity'
|
boolean |
hasFunctor(java.lang.String name,
int arity)
Whether this Term's functor has 'name' and 'arity' (c.f.
|
static Term |
intArrayArrayToList(int[][] a)
Converts an array of arrays of int to a corresponding JPL list of lists
|
static Term |
intArrayToList(int[] a)
Converts an array of int to a corresponding JPL list
|
int |
intValue()
returns the value (as an int) of an Integer or Float
|
boolean |
isAtom()
whether this Term is an Atom (of any type)
|
protected boolean |
isAtomOfNameType(java.lang.String name,
java.lang.String type)
Tests whether this Term is an Atom with name and type.
|
boolean |
isBig()
Tests whether this Integer's value is too big to represent as a long.
|
boolean |
isBigInteger()
Tests whether this Term is an Integer whose value is too big to represent as a long
|
boolean |
isCompound()
Tests whether this Term is a Compound.
|
boolean |
isFloat()
Tests whether this Term is an org.jpl7.Float.
|
boolean |
isInteger()
Tests whether this Term is an org.jpl7.Integer.
|
boolean |
isJFalse()
Tests whether this Term is a 'jfalse' structure, i.e.
|
boolean |
isJNull()
Tests whether this Term is a 'jnull' structure, i.e.
|
boolean |
isJRef()
Tests whether this Term is a (non-null, non-String) JPL reference to a Java object, e.g.
|
boolean |
isJTrue()
Tests whether this Term is a 'jtrue' structure, i.e.
|
boolean |
isJVoid()
Tests whether this Term is a 'jvoid' structure, i.e.
|
boolean |
isList()
whether the Term represents a proper list
|
static boolean |
isList(Term term)
whether the Term represents a proper list
|
boolean |
isListNil()
Tests whether this Term denotes an empty list within the current syntax ("traditional" or "modern").
|
boolean |
isListPair()
Tests whether this Term is a list pair within the current
syntax ("traditional" or "modern").
|
boolean |
isVariable()
Tests whether this Term is a Variable.
|
java.lang.Object |
jrefToObject()
Deprecated.
Use
object() |
int |
listLength() |
static int |
listLength(Term term) |
Term[] |
listToTermArray()
converts a proper list to an array of terms, else throws an exception
|
static Term[] |
listToTermArray(Term t)
converts a proper list to an array of terms, else throws an exception
|
long |
longValue()
The (long) value of a Float or Integer.
|
java.lang.String |
name()
The name of an Atom, Compound or Variable.
|
java.lang.Object |
object()
The Object which this org.jpl7.JRef refers to, iff this Term is a JRef or just JPL.JNULL.
|
static Term |
objectToJRef(java.lang.Object object)
Deprecated.
|
protected abstract void |
put(java.util.Map<java.lang.String,term_t> varnames_to_vars,
term_t term)
Cache the reference to the Prolog term_t here.
|
protected void |
put(term_t term) |
protected Term |
putParams(Term plist) |
Term |
putParams(Term[] params)
This internal method is public because it needs to be callable via JNI, but it is not part of JPL's public API
and should not be used by applications.
|
protected Term |
putParams1(IntHolder next,
Term[] ps) |
protected static Term[] |
putParams2(Term[] ts,
IntHolder next,
Term[] ps) |
static void |
putTerm(java.lang.Object obj,
term_t termref) |
protected static term_t |
putTerms(java.util.Map<java.lang.String,term_t> varnames_to_vars,
Term[] args)
This static method converts an array of Terms to a *consecutive* sequence of term_t objects.
|
java.lang.Object |
ref()
Deprecated.
Use
JRef.object() |
void |
setName(java.lang.String name) |
static Term |
stringArrayToList(java.lang.String[] a)
Converts an array of String to a corresponding JPL list of atoms
|
static Term |
termArrayToList(Term[] terms)
Converts an array of Terms to a JPL representation of a Prolog list of terms whose members correspond to the
respective array elements.
|
static Term |
textParamsToTerm(java.lang.String text,
Term[] params)
Converts a Prolog source text to a corresponding JPL Term (in which each Variable has the appropriate name from
the source text), replacing successive occurrences of ? in the text by the corresponding element of Term[]
params.
|
static Term |
textToTerm(java.lang.String text)
Converts a Prolog source text (as a String) to a corresponding JPL Term
(in which each Variable has the appropriate name from the source text).
|
static java.lang.String |
toString(Term[] args)
Converts a list of Terms to a String.
|
Term[] |
toTermArray()
Deprecated.
|
abstract int |
type()
returns the type of this term, as one of org.jpl7.fli.Prolog.COMPOUND, .ATOM, .VARIABLE, .INTEGER, .FLOAT etc
|
abstract java.lang.String |
typeName()
returns the name of the type of this term, as one of "Compound", "Atom", "Variable", "Integer", "Float" or "JRef"
|
protected Term()
public Term arg(int i)
i
- the index of argument to returnJPLException
- if Term is not a Compoundpublic Term[] args()
Note that a SWI Prolog 7.x compound term can have zero arguments.
This method returns an empty Term[] from an Atom, Float, Integer or JRef, approximating the behaviour of SWI Prolog's =../2
JPLException
- if the Term is a Variablepublic int arity()
JPLException
- if the Term is a Variablepublic java.lang.String atomType()
JPLException
- if the Term is not an Atompublic java.lang.String name()
JPLException
- if this Term is not an Atom, Compound or Variable.public void setName(java.lang.String name)
public static Term textToTerm(java.lang.String text)
text
- A Prolog source text denoting a termPrologException
- containing error(syntax_error(_),_) if text is invalid as a term.public static Term textParamsToTerm(java.lang.String text, Term[] params)
text
- A Prolog source text denoting a termparams
- parameters to be injected in each ?public int intValue()
JPLException
- if this Term is a Compound, Atom or Variablepublic long longValue()
JPLException
- if this Term is not a Float or Integer.public java.math.BigInteger bigValue()
JPLException
- if the Term is not an Integerpublic double doubleValue()
JPLException
- if the Term is neither an Integer nor a Floatpublic float floatValue()
JPLException
- if the Term is neither an Integer nor a Floatprotected static Term getTerm(java.util.Map<term_t,Variable> vars_to_Vars, term_t term)
vars_to_Vars
- A Map from Prolog variables to org.jpl7.Variable instancesterm
- The Prolog term (in a term_t holder) to convertpublic boolean hasFunctor(java.lang.String name, int arity)
name
- a possible name for the functor of a termarity
- an arity 0+JPLException
- if this Term is a Variablepublic boolean hasFunctor(long name, int arity)
For Float and Integer, mimics behaviour of SWI Prolog's functor/3
name
- a possible name for the functor of a termarity
- an arity 0+JPLException
- if this Term is a Variablepublic boolean hasFunctor(java.math.BigInteger name, int arity)
For Float and Integer, mimics behaviour of SWI Prolog's functor/3
name
- a possible name for the functor of a termarity
- an arity 0+JPLException
- if this Term is a Variablepublic boolean hasFunctor(double name, int arity)
For Float and Integer, mimics behaviour of SWI Prolog's functor/3
name
- a possible name for the functor of a termarity
- an arity 0+JPLException
- if this Term is a Variablepublic final boolean isAtom()
protected boolean isAtomOfNameType(java.lang.String name, java.lang.String type)
name
- any Stringtype
- an Atom (blob) type, e.g. "text", "reserved_symbol", "string", "jref"public boolean isBig()
Use this in contexts where the Term is known to be an Integer.
JPLException
- if Term is not an org.jpl7.IntegerisBigInteger()
public boolean isBigInteger()
isBig()
public final boolean isCompound()
public final boolean isFloat()
public final boolean isInteger()
public boolean isJFalse()
public boolean isJNull()
public final boolean isJRef()
JRef.object()
public boolean isJTrue()
public boolean isJVoid()
public final boolean isVariable()
public java.lang.Object object()
JPLException
- if this Term is not a JRef or not NULL term@Deprecated public static final Term objectToJRef(java.lang.Object object)
JPL.newJRef(java.lang.Object)
object
- object of interestJPLException
- if object is a String.protected void put(term_t term)
protected abstract void put(java.util.Map<java.lang.String,term_t> varnames_to_vars, term_t term)
varnames_to_vars
- A Map from variable names to JPL Variables.term
- A (previously created) term_t which is to be put with a Prolog term-type appropriate to the Term type
(e.g., Atom, Variable, Compound, etc.) on which the method is invoked.)public Term putParams(Term[] params)
params
- a list of terms to fill the ? placeholders in the Term objectJPLException
- if there are more actual than formal parameters.public static void putTerm(java.lang.Object obj, term_t termref)
protected static term_t putTerms(java.util.Map<java.lang.String,term_t> varnames_to_vars, Term[] args)
varnames_to_vars
- Map from variable names to JPL Variables.args
- An array of org.jpl7.Term references.@Deprecated public java.lang.Object ref()
JRef.object()
JPLException
- if this Term is not a JRef@Deprecated public java.lang.Object jrefToObject()
object()
protected void getSubst(java.util.Map<java.lang.String,Term> varnames_to_Terms, java.util.Map<term_t,Variable> vars_to_Vars)
A second Map, vars_to_Vars, is required: this table holds the Variables that occur (thus far) in the unified term. The Variable instances in this table are guaranteed to be unique and are keyed on Strings which are Prolog internal representations of the variables.
varnames_to_Terms
- table holding Term substitutions, keyed on names of Variables.vars_to_Vars
- A Map holding the Variables that occur thus far in the term; keyed by internal (Prolog) string rep.protected static void getSubsts(java.util.Map<java.lang.String,Term> varnames_to_Terms, java.util.Map<term_t,Variable> vars_to_Vars, Term[] args)
varnames_to_Terms
- a Map from variable names to Terms (what each variable string is to be replaced by)vars_to_Vars
- a Map from Prolog variables (which may be bounded in the engine) to JPL Variables (which are Java objects)args
- an array of Terms to which the substitution is to be appliedpublic static java.lang.String toString(Term[] args)
args
- An array of Terms to convertpublic abstract int type()
public abstract java.lang.String typeName()
public boolean isListNil()
JPL.getSyntax()
public boolean isListPair()
public final boolean isList()
public static final boolean isList(Term term)
term
- the term to check if it is a listpublic static int listLength(Term term)
term
- any Termpublic int listLength()
public static Term stringArrayToList(java.lang.String[] a)
a
- An array of String objectspublic static Term intArrayToList(int[] a)
a
- An array of int valuespublic static Term intArrayArrayToList(int[][] a)
a
- An array of arrays of int valuespublic static Term termArrayToList(Term[] terms)
terms
- An array of Termpublic static java.lang.String[] atomListToStringArray(Term t)
t
- a term representing a list of atomspublic static Term[] listToTermArray(Term t)
JPLException
- if the term passed is not itself a Prolog list termpublic final Term[] listToTermArray()
JPLException
- if the term passed is not itself a Prolog list term@Deprecated public final Term[] toTermArray()
listToTermArray()