jpl
Class Compound

java.lang.Object
  extended byjpl.Term
      extended byjpl.Compound
Direct Known Subclasses:
Atom

public class Compound
extends Term

A Compound represents a structured term, comprising a functor and arguments (Terms). Atom is a subclass of Compound, whose instances have zero arguments. Direct instances of Compound must have one or more arguments (it is an error to attempt to construct a Compound with zero args; a JPLException will be thrown). For example, this Java expression yields a representation of the term f(a):

 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).
Alternatively, construct the Term from Prolog source syntax:
 Util.textToTerm("f(a)")
 
The arity of a Compound is the quantity of its arguments. Once constructed, neither the name, arity nor any argument of a Compound can be altered.
Copyright (C) 2004 Paul Singleton

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.


Version:
$Revision: 1.2 $
See Also:
Term, Atom

Constructor Summary
Compound(java.lang.String name, Term[] args)
          Creates a Compound with name and args.
 
Method Summary
 Term arg(int i)
          Returns the ith argument (counting from 1) of this Compound; throws an ArrayIndexOutOfBoundsException if i is inappropriate.
 Term arg0(int i)
          Deprecated.  
 Term[] args()
          Deprecated.  
 int arity()
          Returns the arity (1+) of this Compound.
 java.lang.String debugString()
          Deprecated.  
 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'.
 java.lang.String name()
          Returns the name (unquoted) of this Compound.
 java.lang.String toString()
          Returns a prefix functional representation of a Compound of the form name(arg1,...), where each argument is represented according to its toString() method.
 int type()
          returns the type of this term, as one of jpl.fli.Prolog.COMPOUND, .ATOM, .VARIABLE, .INTEGER, .FLOAT etc
 java.lang.String typeName()
          returns the name of the type of this term, as one of "Compound", "Atom", "Variable", "Integer", "Float" etc
 
Methods inherited from class jpl.Term
debugString, doubleValue, floatValue, hasFunctor, hasFunctor, intValue, isAtom, isCompound, isFloat, isInteger, isJBoolean, isJRef, isJVoid, isVariable, listLength, longValue, putParams, putParams, toString, toTermArray
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Compound

public Compound(java.lang.String name,
                Term[] args)
Creates a Compound with name and args.

Parameters:
name - the name of this Compound
args - the arguments of this Compound
Method Detail

arg

public final Term arg(int i)
Returns the ith argument (counting from 1) of this Compound; throws an ArrayIndexOutOfBoundsException if i is inappropriate.

Overrides:
arg in class Term
Returns:
the ith argument (counting from 1) of this Compound

hasFunctor

public final boolean hasFunctor(java.lang.String name,
                                int arity)
Tests whether this Compound's functor has (String) 'name' and 'arity'.

Overrides:
hasFunctor in class Term
Returns:
whether this Compound's functor has (String) 'name' and 'arity'

name

public final java.lang.String name()
Returns the name (unquoted) of this Compound.

Overrides:
name in class Term
Returns:
the name (unquoted) of this Compound

arity

public final int arity()
Returns the arity (1+) of this Compound.

Overrides:
arity in class Term
Returns:
the arity (1+) of this Compound

toString

public java.lang.String toString()
Returns a prefix functional representation of a Compound of the form name(arg1,...), where each argument is represented according to its toString() method.
NB 'name' should be quoted iff necessary, and Term.toString(Term[]) is not really a Term method, more a utility...

Returns:
string representation of an Compound

equals

public final 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.

Parameters:
obj - the Object to compare (not necessarily another Compound)
Returns:
true if the Object satisfies the above condition

type

public int type()
Description copied from class: Term
returns the type of this term, as one of jpl.fli.Prolog.COMPOUND, .ATOM, .VARIABLE, .INTEGER, .FLOAT etc

Specified by:
type in class Term
Returns:
the type of this term, as one of jpl.fli.Prolog.COMPOUND, .ATOM, .VARIABLE, .INTEGER, .FLOAT etc

typeName

public java.lang.String typeName()
Description copied from class: Term
returns the name of the type of this term, as one of "Compound", "Atom", "Variable", "Integer", "Float" etc

Specified by:
typeName in class Term
Returns:
the name of the type of this term, as one of "Compound", "Atom", "Variable", "Integer", "Float" etc

args

public final Term[] args()
Deprecated.  

Returns the arguments of this Compound.

Specified by:
args in class Term
Returns:
the arguments of this Compound

arg0

public final Term arg0(int i)
Deprecated.  

Returns the ith argument (counting from 0) of this Compound.

Returns:
the ith argument (counting from 0) of this Compound

debugString

public java.lang.String debugString()
Deprecated.  

Returns a debug-friendly representation of a Compound.

Specified by:
debugString in class Term
Returns:
a debug-friendly representation of a Compound