com.svincent.moksa
Class PrologTerm

java.lang.Object
  |
  +--com.svincent.moksa.WamObject
        |
        +--com.svincent.moksa.PrologTerm
All Implemented Interfaces:
Trailable
Direct Known Subclasses:
CompoundTerm, Io.StreamIdentifier, JavaTerm, Variable, WamFloat, WamInteger

public abstract class PrologTerm
extends WamObject
implements Trailable

Represents a WAM first-order term (i.e. - a Variable or a CompoundTerm).

Every term has one of the following types

Note that a term of type integer, floating-point, or atom is a constant. This condition can be tested with the isConstant method.


Field Summary
static PrologTerm[] EmptyArray
          A static empty array of PrologTerms.
 
Constructor Summary
PrologTerm(PrologEngine _engine)
           
 
Method Summary
 java.lang.Object accept(PrologTermVisitor v, java.lang.Object parm)
          Allow PrologTermVisitor to access this PrologTerm.
 PrologTerm clonePrologTerm()
           
abstract  PrologTerm clonePrologTerm(java.util.Map objs)
           
 PrologTerm deref()
          Dereferences this PrologTerm, retrieving the PrologTerm that it represents.
 PrologTerm evaluateExpression()
          Evaluates this term as an expression.
 double floatValue()
          Returns this PrologTerm's floating-point value.
 int getArity()
          Retrieve the arity of this term.
abstract  java.lang.String getName()
           
 PrologTerm getNameConstant()
           
 int getPriority()
           
 int intValue()
          Returns this PrologTerm's integral value.
 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 an constant: that is, if it is an Atom, an integer constant, or a floating-point constant.
 boolean isEmptyList()
           
 boolean isFloat()
          Returns true iff this is a floating-point constant.
 boolean isInteger()
          Returns true iff this is a integer constant.
 boolean isJavaObject()
          Returns true iff this is a Java object wrapper.
 boolean isList()
          Returns true iff this is a List.
 boolean isNonEmptyList()
           
 boolean isStreamId()
          Returns true iff this is a Stream Identifier.
 boolean isStructure()
          Return true iff this is a CompoundTerm or an Atom
 boolean isVariable()
          Returns true iff this is a Variable.
 void printVariables(java.io.PrintWriter out)
           
 void setPriority(int _priority)
           
 boolean unify(PrologTerm that)
          Unification algorithm.
abstract  boolean unify(PrologTerm that, boolean doBindings)
          Unification algorithm.
 boolean unifyWithoutBindings(PrologTerm that)
           
 void untrail()
          Default behavior for untrailing is to do nothing.
 
Methods inherited from class com.svincent.moksa.WamObject
tag, 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 PrologTerm[] EmptyArray
A static empty array of PrologTerms.
Constructor Detail

PrologTerm

public PrologTerm(PrologEngine _engine)
Method Detail

getPriority

public int getPriority()

setPriority

public void setPriority(int _priority)

getName

public abstract java.lang.String getName()

getArity

public int getArity()
Retrieve the arity of this term. All terms other than compound terms have an arity of 0.

getNameConstant

public PrologTerm getNameConstant()

intValue

public int intValue()

Returns this PrologTerm's integral value. Only certain prologTerm types can be viewed this way: the others throw exceptions.


floatValue

public double floatValue()

Returns this PrologTerm's floating-point value. Only certain prologTerm types can be viewed this way: the others throw exceptions.


accept

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

isVariable

public boolean isVariable()
Returns true iff this is a Variable.

isJavaObject

public boolean isJavaObject()
Returns true iff this is a Java object wrapper.

isStructure

public boolean isStructure()
Return true iff this is a CompoundTerm or an Atom

isCompoundTerm

public boolean isCompoundTerm()
Returns true iff this is a CompoundTerm.

isList

public boolean isList()
Returns true iff this is a List.

isEmptyList

public boolean isEmptyList()

isNonEmptyList

public boolean isNonEmptyList()

isInteger

public boolean isInteger()
Returns true iff this is a integer constant.

isFloat

public boolean isFloat()
Returns true iff this is a floating-point constant.

isAtom

public boolean isAtom()
Returns true iff this is an Atom.

isConstant

public boolean isConstant()
Returns true iff this is an constant: that is, if it is an Atom, an integer constant, or a floating-point constant.

isStreamId

public boolean isStreamId()
Returns true iff this is a Stream Identifier.

deref

public PrologTerm deref()
Dereferences this PrologTerm, retrieving the PrologTerm that it represents. This has no effect except for Variables.

Unbound variables and all other PrologTerms return themselves.


unify

public boolean unify(PrologTerm that)
Unification algorithm. Can cause variables to become bound. (There is a rollback mechanism to undo these bindings.)

Returns:
true iff the two PrologTerms successfully unify.

unifyWithoutBindings

public boolean unifyWithoutBindings(PrologTerm that)

unify

public abstract boolean unify(PrologTerm that,
                              boolean doBindings)
Unification algorithm.
Parameters:
doBindings - Pass in true if you want matched variables to be bound.
Returns:
true iff the two PrologTerms successfully unify.

clonePrologTerm

public PrologTerm clonePrologTerm()

clonePrologTerm

public abstract PrologTerm clonePrologTerm(java.util.Map objs)

evaluateExpression

public PrologTerm evaluateExpression()
                              throws PrologException
Evaluates this term as an expression.

untrail

public void untrail()

Default behavior for untrailing is to do nothing.

Note that since most PrologTerms are never placed on the trail stack, this method will not be called for many PrologTerm types (CompoundTerms and Numbers come to mind)

Specified by:
untrail in interface Trailable

printVariables

public void printVariables(java.io.PrintWriter out)



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.