public interface Term
Modifier and Type | Method and Description |
---|---|
void |
backtrack()
Reverts this term back to its original state prior to any unifications.
|
Term |
copy(Map<Variable,Variable> sharedVariables)
Returns a copy of this term.
|
Term[] |
getArgs()
Returns an array of this terms's arguments.
|
Term |
getArgument(int index)
Returns the term at the specified position in this term's arguments.
|
default Term |
getBound()
Returns the term this object is bound to.
|
String |
getName()
Returns a string representation of this term.
|
int |
getNumberOfArguments()
Returns the number of arguments in this term.
|
Term |
getTerm()
Returns the current instantiated state of this term.
|
TermType |
getType()
Returns the
TermType represented by this term. |
boolean |
isImmutable()
Returns
true is this term is immutable. |
boolean |
unify(Term t)
Attempts to unify this term to the specified term.
|
String getName()
Exact value returned will vary by TermType
.
Term[] getArgs()
Note: for performance reasons the array returned is the same array used internally be the term instance so be careful not to alter the array returned as changes will be reflected in the original term.
getArgument(int)
int getNumberOfArguments()
Term getArgument(int index)
index
- index of the argument to returnArrayIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= getNumberOfArguments()
)TermType getType()
TermType
represented by this term.TermType
this term representsTerm copy(Map<Variable,Variable> sharedVariables)
The returned copy will share any immutable terms contained in this term. The returned copy will contain new
instances for any Variable
s contained in this term. The sharedVariables
parameter keeps track of
which Variable
s have already been copied.
sharedVariables
- keeps track of which Variable
s have already been copied (key = original version,
value = version used in copy)default Term getBound()
For anything other than a Variable
this method will return this
. TODO think of a better name and
explanation.
Term getTerm()
Returns a representation of this term with all instantiated Variable
s replaced with the terms they are
instantiated with.
Variable
s replaced with the terms they are
instantiated with.boolean unify(Term t)
The rules for deciding if two terms are unifiable are as follows:
Variable
will unify with any term. As a result the Variable
will become
instantiated to the other term. The instantiaton will be undone when backtrack()
is next called on the
Variable
TermType
and have the same value.
The exact meaning of "having the same value" will vary between term types but will include that the two terms
being unified have the same number of arguments and that all of their corresponding arguments unify.t
- the term to unify this term againsttrue
if the attempt to unify this term to the given term was successfulbacktrack()
void backtrack()
Makes all Variable
s that this term consists of uninstantiated.
unify(Term)
boolean isImmutable()
true
is this term is immutable.
A term is considered immutable if its value will never change as a result of executing its unify(Term)
or
backtrack()
methods. A term will not be considered immutable if it is a Variable
or any of its
arguments are not immutable.
true
is this term is immutableCopyright © 2024. All rights reserved.