Class Variable
java.lang.Object
org.projog.core.term.Variable
- All Implemented Interfaces:
Term
Represents an unspecified
Term.
A Variable can be either instantiated (representing another single Term) or uninstantiated (not
representing any other Term). Variables are not constants. What Term, if any, a
Variable is instantiated with can vary during its life time. A Variable becomes instantiated by calls
to unify(Term) and becomes uninstantiated again by calls to backtrack().
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidReverts this variable to an uninstantiated state.Returns a copy of this term.getArgument(int index) CallsTerm.getArgument(int)on theTermthis variable is instantiated with.getAttributeOrDefault(VariableAttribute attributeKey, Term defaultValue) getBound()Returns the term this object is bound to.getId()getName()CallsTerm.getName()on theTermthis variable is instantiated with.intCallsTerm.getNumberOfArguments()on theTermthis variable is instantiated with.getTerm()Returns the current instantiated state of this term.getType()booleanbooleanAlways returnsfalseeven if instantiated with an immutableTerm.voidputAttribute(VariableAttribute attributeKey, Term attributeValue) voidremoveAttribute(VariableAttribute attributeKey) toString()booleanAttempts to unify this term to the specified term.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Term
copy, firstArgument, fourthArgument, secondArgument, thirdArgument
-
Field Details
-
ANONYMOUS_VARIABLE_ID
- See Also:
-
-
Constructor Details
-
Variable
public Variable()Creates an anonymous variable. The ID of the variable will be an underscore. -
Variable
- Parameters:
id- value by which this variable can be identified
-
-
Method Details
-
getAttributeOrDefault
-
putAttribute
-
removeAttribute
-
getName
CallsTerm.getName()on theTermthis variable is instantiated with.- Specified by:
getNamein interfaceTerm- Returns:
- a string representation of this term
- Throws:
NullPointerException- if theVariableis currently uninstantiated
-
getId
- Returns:
- value provided in constructor by which this variable can be identified
-
isAnonymous
public boolean isAnonymous() -
getNumberOfArguments
public int getNumberOfArguments()CallsTerm.getNumberOfArguments()on theTermthis variable is instantiated with.- Specified by:
getNumberOfArgumentsin interfaceTerm- Returns:
- number of arguments in this term
- Throws:
NullPointerException- if theVariableis currently uninstantiated
-
getArgument
CallsTerm.getArgument(int)on theTermthis variable is instantiated with.- Specified by:
getArgumentin interfaceTerm- Parameters:
index- index of the argument to return- Returns:
- the term at the specified position in this term's arguments
- Throws:
NullPointerException- if theVariableis currently uninstantiated
-
unify
Description copied from interface:TermAttempts 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 whenTerm.backtrack()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.
- An uninstantiated
-
getType
- Specified by:
getTypein interfaceTerm- Returns:
TermType.VARIABLEif this variable is uninstantiated else callsTerm.getType()on theTermthis variable is instantiated with.
-
isImmutable
public boolean isImmutable()Always returnsfalseeven if instantiated with an immutableTerm.- Specified by:
isImmutablein interfaceTerm- Returns:
false
-
copy
Description copied from interface:Term -
getBound
-
getTerm
Description copied from interface:TermReturns 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.- Specified by:
getTermin interfaceTerm- Returns:
- itself if this variable is uninstantiated else calls
Term.getType()on theTermthis variable is instantiated with.
-
backtrack
-
toString
-