public abstract class Term
extends java.lang.Object
Copyright (C) 1998 Fred Dushin
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library Public License for more details.
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 (and hence Atom); throws a JPLException for other Term subclasses
|
Term[] |
args()
returns, as a Term[], the arguments of a Compound returns an empty Term[] from an Atom, Integer or Float throws a JPLException from a Variable
|
int |
arity()
returns, as an int, the arity of a Compound, Atom, Integer or Float; throws a JPLException from a Variable
|
java.lang.String |
atomType() |
java.math.BigInteger |
bigValue()
returns the value (as a java.math.BigInteger) of an Integer; throws a JPLException from a Compound, Atom, Float or Variable
|
double |
doubleValue()
returns the value (as a double) of an Integer or Float throws a JPLException from any other subclass
|
float |
floatValue()
returns the value (as a float) of an Integer or Float throws a JPLException from a Compound, Atom or Variable
|
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.
|
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(double value,
int arity)
Tests whether this Term's functor has (double) 'name' and 'arity' Returns false if called inappropriately
|
boolean |
hasFunctor(int value,
int arity)
Tests whether this Term's functor has (int) 'name' and 'arity' Returns false if called inappropriately
|
boolean |
hasFunctor(java.lang.String name,
int arity)
Tests whether this Term's functor has (String) 'name' and 'arity' Returns false if called inappropriately
|
int |
intValue()
returns the value (as an int) of an Integer or Float throws a JPLException from a Compound, Atom or Variable
|
boolean |
isAtom()
whether this Term is an Atom (of some kind)
|
boolean |
isBigInteger()
whether this Term is an Integer whose value is too big to represent as a long
|
boolean |
isCompound()
whether this Term represents a compound term
|
boolean |
isFloat()
whether this Term represents a float
|
boolean |
isInteger()
whether this Term represents an integer
|
boolean |
isJFalse()
whether this Term is a 'jfalse' structure, i.e.
|
boolean |
isJNull()
whether this Term is a 'jnull' structure, i.e.
|
boolean |
isJObject()
whether this Term is a 'jobject' structure, i.e.
|
boolean |
isJRef()
whether this Term is a 'jref' structure, i.e.
|
boolean |
isJTrue()
whether this Term is a 'jtrue' structure, i.e.
|
boolean |
isJVoid()
whether this Term is a 'jvoid' structure, i.e.
|
boolean |
isListNil()
whether this Term denotes (syntax-specifically) an empty list
|
boolean |
isListPair()
whether this Term denotes (syntax-specifically) a list pair
|
boolean |
isVariable()
whether this Term is a variable
|
java.lang.Object |
jrefToObject() |
int |
listLength()
the length of this list, iff it is one, else an exception is thrown
|
long |
longValue()
returns the value (as a long) of an Integer or Float throws a JPLException from a Compound, Atom or Variable
|
java.lang.String |
name()
returns, as a String, the name of a Compound, Atom or Variable throws a JPLException from an Integer or Float
|
static Term |
objectToJRef(java.lang.Object obj)
returns a new Term instance which represents the given object
|
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[] ps) |
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.
|
protected static boolean |
terms_equals(Term[] t1,
Term[] t2)
This method is used (by Compound.equals) to determine the Terms in two Term arrays are pairwise equal, where two Terms are equal if they satisfy the equals predicate (defined differently in
each Term subclass).
|
static java.lang.String |
toString(Term[] args)
Converts a list of Terms to a String.
|
Term[] |
toTermArray()
returns an array of terms which are the successive members of this list, if it is a list, else throws an exception
|
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" etc
|
protected Term()
public Term arg(int i)
public Term[] args()
public java.lang.String atomType()
public boolean hasFunctor(java.lang.String name, int arity)
public boolean hasFunctor(int value, int arity)
public boolean hasFunctor(double value, int arity)
public java.lang.String name()
public int arity()
public int intValue()
public long longValue()
public float floatValue()
public java.math.BigInteger bigValue()
public double doubleValue()
public abstract int type()
public abstract java.lang.String typeName()
public boolean isAtom()
public boolean isBigInteger()
public boolean isCompound()
public boolean isFloat()
public boolean isInteger()
public boolean isVariable()
public boolean isListNil()
public boolean isListPair()
public boolean isJFalse()
public boolean isJNull()
public boolean isJObject()
public boolean isJRef()
public boolean isJTrue()
public boolean isJVoid()
public java.lang.Object jrefToObject()
public static Term objectToJRef(java.lang.Object obj)
public int listLength()
JPLException
public Term[] toTermArray()
JPLException
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.)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.public static void putTerm(java.lang.Object obj, term_t termref)
protected 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 convertprotected 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, 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.
bindings
- table holding Term substitutions, keyed on names of Variables.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 Termsvars_to_Vars
- a Map from Prolog variables to JPL Variablesargs
- an array of Termsprotected static boolean terms_equals(Term[] t1, Term[] t2)
t1
- an array of Termst2
- another array of Termspublic static java.lang.String toString(Term[] args)
args
- An array of Terms to convert