jpl

Class Compound

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 nor the arity of a Compound can be altered. An argument of a Compound can be replaced with the setArg() method.
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.


See Also: Term Atom

Constructor Summary
Compound(String name, Term[] args)
Creates a Compound with name and args.
Compound(String name, int arity)
Creates a Compound with name and arity.
Method Summary
Termarg(int i)
Returns the ith argument (counting from 1) of this Compound; throws an ArrayIndexOutOfBoundsException if i is inappropriate.
Termarg0(int i)
Returns the ith argument (counting from 0) of this Compound.
Term[]args()
Returns the arguments of this Compound (1..arity) of this Compound as an array[0..arity-1] of Term.
intarity()
Returns the arity (1+) of this Compound.
StringdebugString()
Returns a debug-friendly representation of a Compound.
booleanequals(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.
booleanhasFunctor(String name, int arity)
Tests whether this Compound's functor has (String) 'name' and 'arity'.
booleanisJFalse()
whether this Term is a 'jboolean' structure denoting Java's false, i.e.
booleanisJNull()
whether this Term is a 'jnull' structure, i.e.
booleanisJObject()
whether this Term is a 'jobject' structure, i.e.
booleanisJRef()
whether this Term is a 'jref' structure, i.e.
booleanisJTrue()
whether this Term is a 'jboolean' structure denoting Java's true, i.e.
booleanisJVoid()
whether this Term is a 'jvoid' structure, i.e.
Stringname()
Returns the name (unquoted) of this Compound.
voidsetArg(int i, Term arg)
Sets the i-th (from 1) arg of this Compound to the given Term instance.
StringtoString()
Returns 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.
inttype()
returns the type of this term, as jpl.fli.Prolog.COMPOUND
StringtypeName()
returns the name of the type of this term, as "Compound"

Constructor Detail

Compound

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

Parameters: name the name of this Compound args the (one or more) arguments of this Compound

Compound

public Compound(String name, int arity)
Creates a Compound with name and arity. This constructor, along with the setArg method, serves the new, native Prolog-term-to-Java-term routine, and is public only so as to be accessible via JNI: it is not intended for general use.

Parameters: name the name of this Compound arity the arity 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.

Returns: the ith argument (counting from 1) 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

args

public final Term[] args()

Deprecated:

Returns the arguments of this Compound (1..arity) of this Compound as an array[0..arity-1] of Term.

Returns: the arguments (1..arity) of this Compound as an array[0..arity-1] of Term

arity

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

Returns: the arity (1+) of this Compound

debugString

public String debugString()

Deprecated:

Returns a debug-friendly representation of a Compound.

Returns: a debug-friendly representation of a Compound

equals

public final boolean equals(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

hasFunctor

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

Returns: whether this Compound's functor has (String) 'name' and 'arity'

isJFalse

public boolean isJFalse()
whether this Term is a 'jboolean' structure denoting Java's false, i.e. @(false)

Returns: whether this Term is a 'jboolean' structure denoting Java's false, i.e. @(false)

isJNull

public boolean isJNull()
whether this Term is a 'jnull' structure, i.e. @(null)

Returns: whether this Term is a 'jnull' structure, i.e. @(null)

isJObject

public boolean isJObject()
whether this Term is a 'jobject' structure, i.e. @(Tag)

Returns: whether this Term is a 'jobject' structure, i.e. @(Tag)

isJRef

public boolean isJRef()
whether this Term is a 'jref' structure, i.e. @(Tag) or @(null)

Returns: whether this Term is a 'jref' structure, i.e. @(Tag) or @(null)

isJTrue

public boolean isJTrue()
whether this Term is a 'jboolean' structure denoting Java's true, i.e. @(fatruelse)

Returns: whether this Term is a 'jboolean' structure denoting Java's true, i.e. @(fatruelse)

isJVoid

public boolean isJVoid()
whether this Term is a 'jvoid' structure, i.e. @(void)

Returns: whether this Term is a 'jvoid' structure, i.e. @(void)

name

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

Returns: the name (unquoted) of this Compound

setArg

public void setArg(int i, Term arg)
Sets the i-th (from 1) arg of this Compound to the given Term instance. This method, along with the Compound(name,arity) constructor, serves the new, native Prolog-term-to-Java-term routine, and is public only so as to be accessible via JNI: it is not intended for general use.

Parameters: i the index (1+) of the arg to be set arg the Term which is to become the i-th (from 1) arg of this Compound

toString

public String toString()
Returns 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.

Returns: string representation of an Compound

type

public int type()
returns the type of this term, as jpl.fli.Prolog.COMPOUND

Returns: the type of this term, as jpl.fli.Prolog.COMPOUND

typeName

public String typeName()
returns the name of the type of this term, as "Compound"

Returns: the name of the type of this term, as "Compound"