public final class List extends Object implements Term
Terms - a head and a tail.
The head and tail can be any Terms - including other Lists. By having a List with a
List as its tail it is possible to represent an ordered sequence of Terms of any length. The end of
an ordered sequence of Terms is normally represented as a tail having the value of an EmptyList.
EmptyList,
ListFactory,
ListUtils| Constructor and Description |
|---|
List(Term head,
Term tail)
Creates a new list with the specified head and tail.
|
| Modifier and Type | Method and Description |
|---|---|
void |
backtrack()
Reverts this term back to its original state prior to any unifications.
|
List |
copy(Map<Variable,Variable> sharedVariables)
Returns a copy of this term.
|
boolean |
equals(Object o) |
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.
|
String |
getName()
Returns
ListFactory.LIST_PREDICATE_NAME. |
int |
getNumberOfArguments()
Returns the number of arguments in this term.
|
List |
getTerm()
Returns the current instantiated state of this term.
|
TermType |
getType()
Returns
TermType.LIST. |
int |
hashCode() |
boolean |
isImmutable()
Returns
true is this term is immutable. |
String |
toString() |
boolean |
unify(Term t1)
Attempts to unify this term to the specified term.
|
public List(Term head, Term tail)
Consider using ListFactory rather than calling directly.
head - the head of the new listtail - the tail of the new listpublic String getName()
ListFactory.LIST_PREDICATE_NAME.getName in interface TermListFactory.LIST_PREDICATE_NAMEpublic Term[] getArgs()
TermNote: 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.
getArgs in interface TermTerm.getArgument(int)public int getNumberOfArguments()
TermgetNumberOfArguments in interface Termpublic Term getArgument(int index)
TermgetArgument in interface Termindex - index of the argument to returnpublic TermType getType()
TermType.LIST.getType in interface TermTermType.LISTpublic boolean isImmutable()
Termtrue is this term is immutable.
A term is considered immutable if its value will never change as a result of executing its Term.unify(Term) or
Term.backtrack() methods. A term will not be considered immutable if it is a Variable or any of its
arguments are not immutable.
isImmutable in interface Termtrue is this term is immutablepublic List getTerm()
Term
Returns a representation of this term with all instantiated Variables replaced with the terms they are
instantiated with.
public List copy(Map<Variable,Variable> sharedVariables)
Termpublic boolean unify(Term t1)
TermThe 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 Term.backtrack() is next called on the
VariableTermType 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.unify in interface Termt1 - the term to unify this term againsttrue if the attempt to unify this term to the given term was successfulTerm.backtrack()public void backtrack()
Term
Makes all Variables that this term consists of uninstantiated.
backtrack in interface TermTerm.unify(Term)Copyright © 2024. All rights reserved.