Interface Term
- All Known Subinterfaces:
Numeric
- All Known Implementing Classes:
Atom, DecimalFraction, EmptyList, IntegerNumber, List, Variable
-
Method Summary
Modifier and TypeMethodDescriptionvoidReverts this term back to its original state prior to any unifications.default Termcopy()Returns a copy of this term.default Termdefault TermgetArgument(int index) Returns the term at the specified position in this term's arguments.default TermgetBound()Returns the term this object is bound to.getName()Returns a string representation of this term.intReturns the number of arguments in this term.getTerm()Returns the current instantiated state of this term.getType()Returns theTermTyperepresented by this term.booleanReturnstrueis this term is immutable.default Termdefault TermbooleanAttempts to unify this term to the specified term.
-
Method Details
-
getName
-
getNumberOfArguments
int getNumberOfArguments()Returns the number of arguments in this term.- Returns:
- number of arguments in this term
-
firstArgument
-
secondArgument
-
thirdArgument
-
fourthArgument
-
getArgument
Returns the term at the specified position in this term's arguments.- Parameters:
index- index of the argument to return- Returns:
- the term at the specified position in this term's arguments
- Throws:
ArrayIndexOutOfBoundsException- if the index is out of range (index < 0 || index >= getNumberOfArguments())
-
getType
-
copy
Returns a copy of this term.The returned copy will share any immutable terms contained in this term. The returned copy will contain new instances for any
Variables contained in this term. ThesharedVariablesparameter keeps track of whichVariables have already been copied.- Parameters:
sharedVariables- keeps track of whichVariables have already been copied (key = original version, value = version used in copy)- Returns:
- a copy of this term
-
copy
-
getBound
Returns the term this object is bound to.For anything other than a
Variablethis method will returnthis. TODO think of a better name and explanation. -
getTerm
Term getTerm()Returns the current instantiated state of this term.Returns a representation of this term with all instantiated
Variables replaced with the terms they are instantiated with.- Returns:
- a representation of this term with all instantiated
Variables replaced with the terms they are instantiated with.
-
unify
Attempts to unify this term to the specified term.The rules for deciding if two terms are unifiable are as follows:
- An uninstantiated
Variablewill unify with any term. As a result theVariablewill become instantiated to the other term. The instantiaton will be undone whenbacktrack()is next called on theVariable - Non-variable terms will unify with other terms that are of the same
TermTypeand 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.
- Parameters:
t- the term to unify this term against- Returns:
trueif the attempt to unify this term to the given term was successful- See Also:
- An uninstantiated
-
backtrack
void backtrack()Reverts this term back to its original state prior to any unifications.Makes all
Variables that this term consists of uninstantiated.- See Also:
-
isImmutable
boolean isImmutable()Returnstrueis this term is immutable.A term is considered immutable if its value will never change as a result of executing its
unify(Term)orbacktrack()methods. A term will not be considered immutable if it is aVariableor any of its arguments are not immutable.- Returns:
trueis this term is immutable
-