public class Compound extends Term
new Compound("f", new Term[] { new Atom("a") })Note the use of the "anonymous array" notation to denote the arguments (an anonymous array of Term).
Util.textToTerm("f(a)")The arity of a Compound is the quantity of its arguments. Once constructed, neither the name nor the arity of a Compound can be altered. An argument of a Compound can be replaced with the setArg() method.
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.
Constructor and Description |
---|
Compound(java.lang.String name)
Creates a Compound with name and no args (which in SWI Prolog V7 is distinct from a text atom of the same name).
|
Compound(java.lang.String name,
Term[] args)
Creates a Compound with name and (zero or more) args.
|
Modifier and Type | Method and Description |
---|---|
Term |
arg(int i)
Returns the ith argument (counting from 1) of this Compound.
|
Term[] |
args()
Returns the arguments of this Compound as a Term[0..arity-1] array.
|
int |
arity()
Returns the arity (0+) of this Compound.
|
boolean |
equals(java.lang.Object obj)
Two Compounds are equal if they are identical (same object) or their names and arities are equal and their
respective arguments are equal.
|
boolean |
hasFunctor(java.lang.String name,
int arity)
Tests whether this Compound's functor has (String) 'name' and 'arity'.
|
boolean |
isJFalse()
whether this Term is a 'jboolean' structure denoting Java's false, i.e.
|
boolean |
isJNull()
whether this Term is a 'jnull' structure, i.e.
|
boolean |
isJTrue()
whether this Term is a 'jboolean' structure denoting Java's true, i.e.
|
boolean |
isJVoid()
whether this Term is a 'jvoid' structure, i.e.
|
boolean |
isListPair()
whether this Term denotes (syntax-specifically) a list cell
|
java.lang.Object |
jrefToObject()
returns null iff this Compound represents @(null)
|
java.lang.String |
name()
the name (unquoted) of this Compound
|
void |
setArg(int i,
Term arg)
Sets the i-th (from 1) arg of this Compound to the given Term instance.
|
java.lang.String |
toString()
a prefix functional representation of a Compound of the form name(arg1,...), where 'name' is quoted iff necessary
(to be valid Prolog soutce text) and each argument is represented according to its toString() method.
|
int |
type()
the type of this term, as jpl.fli.Prolog.COMPOUND
|
java.lang.String |
typeName()
the name of the type of this term, as "Compound"
|
atomType, bigValue, doubleValue, floatValue, hasFunctor, hasFunctor, hasFunctor, intValue, isAtom, isBig, isBigInteger, isCompound, isFloat, isInteger, isJRef, isListNil, isVariable, listLength, longValue, object, objectToJRef, putParams, putTerm, ref, toString, toTermArray
public Compound(java.lang.String name)
name
- the name of this CompoundJPLException
- if name is nullpublic Compound(java.lang.String name, Term[] args)
name
- the name of this Compoundargs
- the (zero or more) arguments of this CompoundJPLException
- if name is null or args is nullpublic final Term arg(int i)
public final Term[] args()
public final int arity()
public final boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the Object to compare (not necessarily another Compound)public final boolean hasFunctor(java.lang.String name, int arity)
hasFunctor
in class Term
name
- a possible name for the functor of a termarity
- an arity 0+public boolean isJFalse()
public boolean isJNull()
public boolean isJTrue()
public boolean isJVoid()
public final boolean isListPair()
isListPair
in class Term
public java.lang.Object jrefToObject()
jrefToObject
in class Term
Term.jrefToObject()
,
Term.jrefToObject()
public final java.lang.String name()
public void setArg(int i, Term arg)
i
- the index (1+) of the arg to be setarg
- the Term which is to become the i-th (from 1) arg of this Compoundpublic java.lang.String toString()
toString
in class java.lang.Object
public int type()