com.svincent.moksa
Class CompoundTerm

java.lang.Object
  |
  +--com.svincent.moksa.WamObject
        |
        +--com.svincent.moksa.PrologTerm
              |
              +--com.svincent.moksa.CompoundTerm
All Implemented Interfaces:
Trailable

public class CompoundTerm
extends PrologTerm

A compoundTerm is a Prolog tree constant (normally of the form f(x1, x2, ..., xn), where f is known as the compoundTerm's functor, and x1 through xn are known as the term's subterms.

The value n is known as the compoundTerm's arity.


Inner Class Summary
static class CompoundTerm.ListWrapper
          A wrapper for a CompoundTerm as a list.
static class CompoundTerm.PrologIterator
           
 
Field Summary
static CompoundTerm[] EmptyArray
           
 
Fields inherited from class com.svincent.moksa.PrologTerm
EmptyArray
 
Constructor Summary
CompoundTerm(PrologEngine _engine, java.lang.String _name, PrologTerm[] _subterms, int _priority)
          Builds a new CompoundTerm with the given name.
 
Method Summary
 java.lang.Object accept(PrologTermVisitor v, java.lang.Object parm)
          Allow PrologTermVisitor to access this PrologTerm.
 CompoundTerm.ListWrapper asList()
           
 PrologTerm clonePrologTerm(java.util.Map objs)
           
 PrologTerm evaluateExpression()
          Evaluates this term as an expression.
 int getArity()
          Retrives this CompoundTerm's arity.
 WamInteger getArityConstant()
          Retrives this CompoundTerm's arity, as a constant.
 java.lang.String getName()
          Retrieves this CompoundTerm's name.
 PrologTerm getNameConstant()
           
 int getPriority()
           
 PrologTerm getSubterm(int idx)
          Retrieves this CompoundTerm's value.
 PrologTerm getSubtermDeref(int idx)
           
 boolean isAtom()
          Returns true iff this is an Atom.
 boolean isCompoundTerm()
          Returns true iff this is a CompoundTerm.
 boolean isConstant()
          Returns true iff this is a constant: i.e.
 boolean isEmptyList()
           
 boolean isInfix()
           
 boolean isList()
          Returns true iff this is a List.
 boolean isNonEmptyList()
           
 boolean isPostfix()
           
 boolean isPrefix()
           
 boolean isStructure()
          Return true iff this is a CompoundTerm or an Atom
protected  void tag(java.io.PrintWriter out)
          Writes a short human-readable representation of this object to the given Writer.
 boolean unify(PrologTerm _that, boolean doBindings)
          Unification algorithm.
 
Methods inherited from class com.svincent.moksa.PrologTerm
clonePrologTerm, deref, floatValue, intValue, isFloat, isInteger, isJavaObject, isStreamId, isVariable, printVariables, setPriority, unify, unifyWithoutBindings, untrail
 
Methods inherited from class com.svincent.moksa.WamObject
tag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EmptyArray

public static final CompoundTerm[] EmptyArray
Constructor Detail

CompoundTerm

public CompoundTerm(PrologEngine _engine,
                    java.lang.String _name,
                    PrologTerm[] _subterms,
                    int _priority)
Builds a new CompoundTerm with the given name. Note that CompoundTerms are intended to be used as constants, so no building API is provided.

Method Detail

getPriority

public int getPriority()
Overrides:
getPriority in class PrologTerm

getName

public java.lang.String getName()
Retrieves this CompoundTerm's name.
Overrides:
getName in class PrologTerm

getNameConstant

public PrologTerm getNameConstant()
Overrides:
getNameConstant in class PrologTerm

getArity

public int getArity()
Retrives this CompoundTerm's arity.
Overrides:
getArity in class PrologTerm

getArityConstant

public WamInteger getArityConstant()
Retrives this CompoundTerm's arity, as a constant.

isStructure

public boolean isStructure()
Return true iff this is a CompoundTerm or an Atom
Overrides:
isStructure in class PrologTerm

isCompoundTerm

public boolean isCompoundTerm()
Returns true iff this is a CompoundTerm.
Overrides:
isCompoundTerm in class PrologTerm

isAtom

public boolean isAtom()
Returns true iff this is an Atom.
Overrides:
isAtom in class PrologTerm

isConstant

public boolean isConstant()
Returns true iff this is a constant: i.e. an Atom, an integer constant, or a floating-point constant.
Overrides:
isConstant in class PrologTerm

getSubterm

public PrologTerm getSubterm(int idx)
Retrieves this CompoundTerm's value.

Parameters:
idx - - the index of the subterm to retrieve: must be in the range 0 through getArity () - 1, inclusively.

getSubtermDeref

public PrologTerm getSubtermDeref(int idx)

accept

public java.lang.Object accept(PrologTermVisitor v,
                               java.lang.Object parm)
Allow PrologTermVisitor to access this PrologTerm.
Overrides:
accept in class PrologTerm

unify

public boolean unify(PrologTerm _that,
                     boolean doBindings)
Unification algorithm. Can cause variables to become bound. (We will eventually have a rollback mechanism to undo these bindings.)

Overrides:
unify in class PrologTerm
Returns:
true iff the two PrologTerms successfully unify.

clonePrologTerm

public PrologTerm clonePrologTerm(java.util.Map objs)
Overrides:
clonePrologTerm in class PrologTerm

evaluateExpression

public PrologTerm evaluateExpression()
                              throws PrologException
Evaluates this term as an expression.
Overrides:
evaluateExpression in class PrologTerm

isInfix

public boolean isInfix()

isPrefix

public boolean isPrefix()

isPostfix

public boolean isPostfix()

isList

public boolean isList()
Description copied from class: PrologTerm
Returns true iff this is a List.
Overrides:
isList in class PrologTerm

isEmptyList

public boolean isEmptyList()
Overrides:
isEmptyList in class PrologTerm

isNonEmptyList

public boolean isNonEmptyList()
Overrides:
isNonEmptyList in class PrologTerm

tag

protected void tag(java.io.PrintWriter out)
Writes a short human-readable representation of this object to the given Writer.

Overrides:
tag in class WamObject

asList

public CompoundTerm.ListWrapper asList()



This is documentation for Moksa Prolog, which can be found at http://www.svincent.com/moksa/

Copyright © 1999 Shawn P. Vincent.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.